[Freeswitch-users] Mod_sms and script to send to Twilio

David Rodrigues drodrig at magicbrain.com
Tue Mar 8 21:09:49 MSK 2016


Thank you. I'm new to the mailing list. I had my mail client set for
html. Perhaps that was the problem. Here is 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)

Here is 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 here is the error (keep in mind that the script actually works
fine. I receive the SMS as expected):

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 at 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 at my.sipdomain.com>;tag=0b2cec63]
to [(XXX)%CX%A0XXX-XXX at my.sipdomain.com]
Test sms
Nobody to send to: Profile internal

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list