首页 > 解决方案 > 图像出现在 dialogflow 聊天机器人中,但未显示在 whatsapp 聊天机器人中并导致 twilio 错误

问题描述

查看更新:部分解决方案

我正在使用 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

我能做些什么来解决这个问题吗?


部分解决方案

下面是部分解决方案

我能够通过对话流实现将图像发送到什么应用程序

首先,在“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

标签: imagetwiliodialogflow-eschatbotwhatsapp

解决方案


我也遇到了同样的问题,即无法将媒体消息发送给当前正在使用聊天机器人的任何用户。我在 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);

}

推荐阅读