1

I'm creating a web app in Python with Bottle which has the task to retrieve messages from Plivo. First, when I send a message to Plivo, it's like if I didn't. I can't find a Python example and I don't know much about web protocols and so on to configure all by myself. I have the following issues which I haven't been able to fix:

1. Setting up Plivo to forward messages. In the site, you can create applications with these input options:

  • Application name
  • Sub account
  • Answer url
  • Answer method
  • Fallback_answer url
  • Fallback method
  • Hangup url
  • Hangup method
  • Message url
  • Message method
  • Default number app
  • Default endpoint app
  • Public uri

Setting up at least part of it should get my messages to my server. I don't know what.

2. I've got the following python code: from bottle import route, run, request

@route('/hello', method=['GET', 'POST'])
def hello():
    return "Hello World!"
    bottlelog = open('bottlelog.txt').read
    bottlelog.append(request + '\n')
    bottlelog.close()

run(host='0.0.0.0', port=8080, debug=True)

It should save the request information in this file but at least right now it doesn't. 3. Answer. Should my server answer something specific when Plivo notifies me of my messages?

I hope that you can help me at least to find out where I should head to resolve my problems. Excuse me if I'm kind of messy, I'm new to web development and I'm just getting to know stuff. Thank you all

Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49
user2542929
  • 27
  • 1
  • 3

1 Answers1

2

Your Plivo number must be linked to an application which has a "Message url" present. When an SMS is received on your number, Plivo will send a hook to the "Message url" with the parameters Text, From, To, Type and MessageUUID. The HTTP method used to send these parameters is the "Message method" set in the application.

Plivo Application

For the setup you described, your bottle server is listening on 8080 and has a route /hello/ open. Your Message Url should be http://<your-server-name>:8080/hello/ and the Message method should be set as POST. Click on "Create" to create your application

Next step is to link your Plivo number to the application you just created. Click on the "Numbers" tab in the dashboard. You will be able to see all your Plivo numbers under the "Your Numbers" section. By clicking on the number you'll be given an option to choose your application. Select the "Receive Message" app and click on "Update".

Attach the application to the number

This sample code should get you up and running.

from bottle import run, request, HTTPResponse

@route('/hello/', method=['POST']) 
def hello(): 
    Text = request.forms.get('Text')
    From = request.forms.get('From')
    print "Message received: %s - by %s" % (Text, From)
    return HTTPResponse(status=200)

run(host='0.0.0.0', port=8080, debug=True)

Run this code on your server and you'll be able to see the incoming messages on the console when an SMS is received on your Plivo number.

tsudot
  • 533
  • 1
  • 6
  • 16