【发布时间】:2020-03-14 01:59:30
【问题描述】:
查看更新:部分解决方案
我正在使用 dailogflow 和 twilio 制作 whatsapp 聊天机器人。
短信在对话流和whatsapp中都正常显示。
图像仅出现在 dialogflow 聊天机器人中,但在 whatsapp 聊天机器人中不起作用,并且在 twilio 中出错
这是我添加到 DialogFlow 实现的内联编辑器的代码部分:
agent.add(new Card({
title: `Title: this is a card title`,
imageUrl: 'http://examplesitelink.com/image_name.png',
})
在我在 twilio 中收到的错误消息下方
MESSAGE
The URI scheme, of the URI null, must be equal (ignoring case) to 'http', 'https', 'ws', or 'wss'
......
HTTP retrieval failure
......
Possible Causes
Web server returned a 4xx or 5xx HTTP response to Twilio
Misconfigured Web Server
Network disruptions between Twilio and your web server
No Content-Type header attached to response
Content-Type doesn't match actual content, e.g. an MP3 file that is being served with Content-Type: audio/x-wav, instead of Content-Type: audio/mpeg
有什么办法可以解决这个问题吗?
部分解决方案
下面的部分解决方案
我能够通过对话流实现将图像发送到 whats 应用程序
首先,在“package.json”中,我在依赖项中添加了 twilio,“twilio”:“3.37.1”(在 npm twilio 上查看最新版本)
其次,我添加了下面的代码,以使用其 url 将图像发送到 whatsapp,它可以工作
const client = require('twilio')('YOUR_ACCOUNT_SID', 'YOUR_AUTH_TOKEN'); /* change YOUR_ACCOUNT_SID and YOUR_AUTH_TOKEN to your own twilio account data */
client.messages
.create({
to: 'whatsapp:+13233633791', /* change it to your the number which you want to send the image to*/
from: 'whatsapp:+18007778888', /* change it to your the number which twilio sandbox provide, you can find it here: https://www.twilio.com/console/sms/whatsapp/sandbox */
body: "Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.",
mediaUrl: 'https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG',
})
.then((message) => console.log(message.sid));
现在的问题是:
在之前的代码中,to 是必需的,这意味着我必须指定要将图像发送到的号码,这看起来很奇怪,但如果我没有指定 to,则代码将不起作用。
我需要知道的是,我该如何更改:to: 'whatsapp:+13233633791', 任何代码都可以发送消息到current user who use whatsapp
【问题讨论】:
-
并非每个平台都支持卡片 - 您可以在cloud.google.com/dialogflow/docs/intents-rich-messages#card了解更多信息
-
感谢您的回复,有没有办法在没有卡的情况下插入图片?
标签: image twilio dialogflow-es chatbot whatsapp