使用twilio whatsapp api发送图像/文件

问题描述 投票:1回答:5

尝试用沙盒(https://www.twilio.com/docs/sms/whatsapp/api#twilio-sandbox-for-whatsapp)发送消息的twilio whatsapp api并且它成功了。但是,当尝试发送图像文件时,它在仪表板中显示错误为'12400发生内部错误,导致Twilio无法处理您的响应。使用了与发送消息相同的格式,但参数已更改为“MediaUrl”。

1)发送图像文件时还有其他事项需要注意吗? 2)是否可以使用twilio的whatsapp api发送excel / pdf等附件?

twilio twilio-api
5个回答
2
投票

它尚不支持。

适用于WhatsApp的Twilio API

https://www.twilio.com/docs/sms/whatsapp/api#sending-a-freeform-whatsapp-message-using-the-api

“支持在出站邮件中发送媒体即将推出。”


0
投票

好吧,只有twilio whatsapp发送的媒体不受支持,但有文字可以发送,如果你只愿意发送图像,那么在你的邮件正文中添加空间就可以了。

在PHP中查看我的代码

$get_response = $client->messages->create(
    $phone, array(
        'from' => $sender_id, //Whatsapp:+1xxxxxxxxxx
        'body' => " ", //Add blank space here
        'mediaUrl' => $mediaUrl, //http://example.com/mms_file/image.jpg
    )
);

在这里我在身体中添加空白区域,我开始接收图像。


0
投票

看起来现在有可能。

要发送包含媒体附件的自由格式WhatsApp消息,请在消息中包含MediaUrl参数。支持的媒体包括图像(JPG,JPEG,PNG),音频文件和PDF。每封邮件支持一个媒体附件,大小限制为5MB。

https://www.twilio.com/docs/sms/whatsapp/api#sending-a-freeform-whatsapp-message-with-media-attachment

尽管入境仍在进行中:

即将推出对入站媒体和位置的支持。


0
投票
const string accountSid = "ACxxxxxxxxx....";
const string authToken = "b4xxxxx......";
Uri img = new Uri("http://youserver.com/images/filename.jpeg");
List<Uri> listImg = new List<Uri>();
listImg.Add(img);

TwilioClient.Init(accountSid, authToken);

var message = MessageResource.Create(
                body: "Hello word!",
                from: new Twilio.Types.PhoneNumber("whatsapp:+1xxxxxxxx"),
                to: new Twilio.Types.PhoneNumber("whatsapp:+1xxxxxxxxx"),
                mediaUrl: listImg);            

0
投票

尽管Twilio中的WhatsApp API集成仍处于测试阶段,他们正在与WhatsApp团队合作以实现最佳集成,但我已成功通过沙箱环境发送了MP3音频消息。

逻辑是:

从WhatsApp应用程序,我发送消息到Twilio沙箱号码。 - Twilio接收消息并通过webhook转发(POST)到我在Heroku中托管的Node.js应用程序端点。 - Heroku节点应用程序接收消息并执行一些逻辑。 - 逻辑完成后,我需要在我使用的片段下面回复一条短信,然后是一条音频信息:

const client = require('twilio')(accountSid, authToken); 
const MessagingResponse = require('twilio').twiml.MessagingResponse;
const twiml = new MessagingResponse();

//Text Message 
var msg = twiml.message("Text Message");//Text Message
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());

//Audio Message
client.messages
   .create({
       to: req.body.From,//req is the request arrived from the Twilio forward webhook
       from: req.body.To,
       body: "",
       mediaUrl: "http://www.example.com/audio/test.mp3",
   })
   .then((message) => console.log(message.sid));

当音频消息到达WhatsApp应用程序时,您可以直接收听它,而无需浏览托管音频的链接。

请记住,WhatsApp可以阻止消息,但在这种情况下,您应该在Twilio Dashboard中看到错误日志。

© www.soinside.com 2019 - 2024. All rights reserved.