【问题标题】:image appears in dialogflow chatbot but not shown in whatsapp chatbot and making twilio error图像出现在 dialogflow 聊天机器人中,但未显示在 whatsapp 聊天机器人中并导致 twilio 错误
【发布时间】: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

【问题讨论】:

标签: image twilio dialogflow-es chatbot whatsapp


【解决方案1】:

我也遇到了同样的问题,即无法将媒体消息发送给当前正在使用聊天机器人的任何用户。我在 youtube 视频中找到了解决方案,他们在其中提取了接收器手机号码。来自如下的请求对象 -

const data = request.body.originalDetectIntentRequest.payload;
const To = data.From;
const From = data.To;

这里的请求对象是您在使用此处“req”下面的代码创建对话流代理时获得的对象-

app.post("/", express.json(), (req, res) => {
    -------------------
    -------------------
    function handler() {
         ----------
    }
    intentMap.set("intent", handler);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多