Mod_sms and script to send to Twilio

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Mod_sms and script to send to Twilio

drodrig
This post has NOT been accepted by the mailing list yet.
Hi all.

I wrote a small Python script that is run from a chatplan and takes a chat message from a sip extension and sends the message to the appropriate phone number via Twilio (they provide an Internet-based API to do this). The script works great, but I still see an error in on fs_cli console:


2016-03-05 15:17:54.040913 [DEBUG] mod_python.c:286 Finished calling python script 
2016-03-05 15:17:54.040913 [WARNING] sofia_presence.c:221 Not sending to local box for (XXX)%CX%A0XXX-XXX@my.sipdomain.com <-- (Note that I substituted Xs for the actual phone digits just for this post)
2016-03-05 15:17:54.040913 [ERR] sofia_presence.c:272 Chat proto [sip]
from ["d100" <sip:100@my.sipdomain.com>;tag=0b2cec63]
to [(XXX)%CX%A0XXX-XXX@my.sipdomain.com]
Test sms
Nobody to send to: Profile internal

I've tried mucking with the "to" and "to_user" headers (and other headers  as well). I've also tried adding the following line in the chatplan XML file:

<action name="stop" data=""/>

Finally, I've tried different return values in the Python script.

Nothing I've tried removes the error messages. In truth, the texting works fine -- I just don't like seeing the error.

Here's my chatplan XML file:
<?xml version="1.0" encoding="utf-8"?>
<include>
    <context name="public">
		<extension name="100">
            <condition field="to" expression="^(.*)$">
                <action application="python" data="sms"/> 
            </condition>
        </extension>
	</context>
</include>

And the python script:
#/usr/bin/env python

import re
import pprint
import sys
import urllib
import subprocess 

from freeswitch import *

ACCOUNTSID = 'my-account-sid'
AUTHTOKEN = 'my-auth-token'
PHONENUMBER = '+my-source-phone-number'

def chat(message, args):
    to_phone = '+1' + re.sub('\D', '', urllib.unquote(message.getHeader('to_user'))).lstrip('+1')
    body = message.getBody()
    subprocess.call("curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/'" + ACCOUNTSID +
         "/Messages.json --data-urlencode 'To=" + to_phone + "' --data-urlencode " +
         "'From=+" + PHONENUMBER + "' --data-urlencode 'Body=" + body + "' -u " +
         ACCOUNTSID + ":" + AUTHTOKEN, shell=True)

I'm new to the world of SIP and Freeswitch, so I am hoping I am missing something simple.

Any help is appreciated.