Issue
hi i’m new in flask and twilio, i’m try to send 2 images with 1 request but just appears the last image that i put in the array
this is my code
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)
how could see in the "media_url" parameter i put 2 urls, but twilio just send my 1, i made a mistake?. i try it in this way too
mss = MessagingResponse()
resp = mss.message("this is a message")
resp.body("imagen1")
resp.media("https://demo.twilio.com/owl.png")
resp.body("imagen2")
resp.media("https://demo.twilio.com/bunny.png")
return str(resp)
but is the same. thnks for ur help
Solution
Twilio developer evangelist here. That code should work, it’s just that there is no bunny image at that URL. You will need your image to be hosted at a publicly-accessible URL like these:
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"],
)
That returns this image:
I’d recommend using Twilio Runtime Assets, our static file hosting service that allows developers to quickly upload and serve the files needed to support their applications. host your files that support web, voice, and messaging applications. Assets is commonly used to host .mp3 audio files used in TwiML, to serve images sent through MMSes, or store configuration used by Twilio Functions. You can also deploy the images to be hosted on web servers.
Let me know if this helps at all!
Answered By – lizziepika
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0