一个灵活且易于使用的包,用于构建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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
切换名称节点Hadoop Java api和camel、jms   java首先执行服务器调用,然后执行下一行代码   java如何登录到这样的站点?   C#AES在Java中使用CFB NoPadding模式进行加密   JVM中的java确定性垃圾收集   java在与PC相连的移动设备上读写数据   java jar编译运行时。getRuntime。exec()jar中的完整目录   java HTTP状态500无法转换类型的值   如何获取另一种语言的Java日期   java无法使用安卓 emulator连接到本地服务器   java计算窗口内两个Swing组件的焦点遍历距离   Java字符串将错误与正则表达式匹配   java将请求从servlet发送到jsp   math Java cast未生成预期输出   在Java中,获取字符串最后250个字符的最佳方法是什么?   Java线程同步管理中的静态关键字   项目中的java Eclipse错误   数组JAVA从txt文件读取整数并计算整数