简体   繁体   中英

Twilio python MessagingResponse.message.media not working for a mp3 audio

@app.route('/bot', methods=['POST'])
def bot():

    content = request.form.get('Body').lower()

    resp = MessagingResponse()
    msg = resp.message()

    responded = False

    if 'hi' in content:
        msg.media(url_for('static', filename='bonjour.mp3'), content_type='audio/mpeg')
        responded = True
    if not responded:
        msg.body('no')
    return str(resp)

That's my code to respond to a Whatsapp message. If you say 'hi', it should send you an mp3 audio that i saved (I checked that the path is correct), and if you say something else it just says 'no'. But when I send a message with 'hi', I get this error in the Twilio debug part: error 12200

The URL you pass to media() needs to be an absolute URL of a media file which is publicly available, not a relative one.

In your case not /static/bonjour.mp3 but something like https://yourdomain.com/static/bonjour.mp3 .

Also omit the content_type .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM