Created
June 30, 2017 11:57
-
-
Save willwhui/fd511cee75153bc73d51f451f3d9e0a2 to your computer and use it in GitHub Desktop.
搭建api.ai webhook(在朋友google cloud搭建的vps上使用python+flask+jinja)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
搭建api.ai webhook(在朋友google cloud搭建的vps上使用python+flask+jinja) |
根据api.ai Action返回不同的结果
这里有简单示例
根据action来判断应该执行何种动作
让Google Home播放mp3文件
var msg = `
<speak>
Tone one
<audio src="https://examaple.com/wav/Dtmf-1.wav"></audio>
Tone two
<audio src="https://example.com/wav16/Dtmf-2.wav"></audio>
Foghorn
<audio src="https://example.com/mp3/foghorn.mp3"></audio>
Done
</speak>
`;
var reply = {
speech: msg,
data:{
google:{
"expect_user_response": true,
"is_ssml": true
}
}
};
res.send( reply );
以上js代码的关键点在于:
- api.ai的webhook返回字段的“speech"部分用msg来填充
- 增加data字段
- msg要符合google home要求的"SSML"规范
参见google的文档:Format of response from the webhook
根据SSML规范,speak字段中可以返回文本和mp3文件链接的混合物。
在flask中使用静态文件返回指向mp3的json
参见这里:
只需要在template同级目录建立static目录就可以直接输入完整网址访问此目录下的所有文件
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
webhook错误206排除
绑定域名,设定了ssl之后,api.ai依然返回错误:
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: Webhook response was empty."
},
服务器返回json的函数依然没有被调用到。
尝试在python3命令行中进行如下操作:
失败:requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
成功。
说明ssl有问题。
经过一番查找,发现这里(stackoverflow)的答案:
在nginx的配置中,必须使用“fullchan.pem”
ssl_certificate /etc/letsencrypt/live/mydomainname/fullchain.pem;
重启nginx之后,在python命令行中运行requests.get成功。