一个灵活且易于使用的包,用于构建Alexa Skill应用程序。
alexa-skill的Python项目详细描述
Alexa技能
^ a1}是灵活的,易于使用和扩展包以创建Alexa技能应用程序。
这个包基于alexa documentation。
安装
使用pip安装和更新:
pip install -U alexa-skill
示例
定义意图类
fromalexa_skill.intentsimportBaseIntentsclassExampleIntents(BaseIntents):@propertydefmapper(self):return{'EXAMPLE.hello':self.hello,}defhello(self):returnself.response('Hello. Nice to meet you.'),True
用插槽定义意图类
fromalexa_skillimportdatesfromalexa_skill.intentsimportBaseIntentsclassDateIntents(BaseIntents):@propertydefmapper(self):return{'EXAMPLE.date_intent':self.date_intent,}defdate_intent(self,slots):date,date_type=dates.AmazonDateParser.to_date(slots['dateslot']['value'])text="Your date is <say-as interpret-as='date'>{}</say-as> and it is a {}".format(date.strftime('%Y%m%d'),date_type)returnself.response(text),True
定义内置意图
fromalexa_skill.intentsimportBuildInIntentsbuildin_intents=BuildInIntents(help_message='Say "HI" to us',not_handled_message="Sorry, I don't understand you. Could you repeat?",stop_message='stop',cancel_message='cancel')
Falcon
在Fulfiller Webhook for Alexa中启动意图
importloggingimportalexa_skillimportfalconclassFulfiller(object):defon_post(self,req,resp):get_response=alexa_skill.Processor(req.media,buildin_intents,'Welcome to Alexa skill bot','Good bye',ExampleIntents(),# Insert created Intents as argumentsDateIntents(),)json_response,handled=get_response()logging.info('Response was handled by system: {}'.format(handled))resp.media=json_responseapp=falcon.API(media_type=falcon.MEDIA_JSON)app.add_route('/v1/alexa/fulfiller',Fulfiller())
Flask
importloggingimportalexa_skillfromflaskimportFlask,request,jsonifyapp=Flask(__name__)@app.route("/v1/alexa/fulfiller",methods=['POST'])deffulfiller():get_response=alexa_skill.Processor(request.json,buildin_intents,'Welcome to Alexa skill bot','Good bye',ExampleIntents(),DateIntents(),)json_response,handled=get_response()logging.info('Response was handled by system: {}'.format(handled))returnjsonify(json_response)
文档
自动生成文档
cd docs/
sphinx-apidoc -o ./source/_modules/ ../alexa_skill/
make html