问题描述
嗨,我是 Flask 和 twilio 的新手,我尝试用 1 个请求发送 2 个图像,但只显示我放入数组中的最后一个图像
这是我的代码
// child of some widgets like container
child: SfCartesianChart(
primaryXAxis: CategoryAxis(),legend: Legend(isVisible: false),tooltipBehavior: TooltipBehavior(enable: true),series: <ChartSeries<_SalesData,String>>[
Lineseries<_SalesData,String>(
dataSource: data,xValueMapper: (_SalesData sales,_) =>sales.year.toString(),yValueMapper: (_SalesData sales,_) =>sales.value,),],
如何在“media_url”参数中看到我输入了 2 个 url,但 twilio 只发送了我的 1 个,我犯了一个错误?。我也是这样试的
from flask import Flask,request
from twilio.twiml.messaging_response import MessagingResponse
from twilio.rest import Client
from dotenv import load_dotenv
import os
load_dotenv()
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello,World!"
@app.route("/sms",methods=['POST'])
def sms_reply():
"""Respond to incoming calls with a simple text message."""
# Fetch the message
msg = request.form.get('Body')
# CLIENT
client = Client(os.getenv("TWILIO_ID"),os.getenv("AUTH_TOKEN"))
number = request.values.get('From','')
# creating the message
if msg == "imagen":
message = client.messages.create(
from_='whatsapp:+14155238886',media_url=["https://demo.twilio.com/owl.png","https://demo.twilio.com/bunny.png"],to=number
)
resp = MessagingResponse()
resp.message("imagen : {}".format(message.body))
return str(resp)
但是是一样的。谢谢你的帮助
解决方法
Twilio 开发者布道者在这里。该代码应该可以工作,只是该 URL 上没有兔子图像。您需要将图片托管在可公开访问的网址中,如下所示:
message = client.messages.create(
from_="YOUR-TWILIO-NUMBER",to="NUMBER-TO-RECEIVE-IMAGES",body="Test sending two messages",media_url=["https://data.whicdn.com/images/339398954/original.gif","https://thumbs.gfycat.com/PrestigiousUntidyBetafish-max-1mb.gif"],)
返回这个图像: 我建议使用 Twilio Runtime Assets,这是我们的静态文件托管服务,允许开发人员快速上传和提供支持其应用程序所需的文件。托管支持 Web、语音和消息传递应用程序的文件。 Assets 通常用于托管 TwiML 中使用的 .mp3 音频文件,提供通过 MMS 发送的图像,或存储 Twilio Functions 使用的配置。您还可以部署要托管在网络服务器上的图像。
让我知道这是否有帮助!