-
-
Save andres-torres-marroquin/27168a6b1c149d40b30b to your computer and use it in GitHub Desktop.
Callfire API on python suds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from suds.client import Client | |
url = 'https://callfire.com/api/1.1/wsdl/callfire-service-http-soap12.wsdl' | |
client = Client(url, username=CALLFIRE_USERNAME, password=CALLFIRE_PASSWORD) | |
### Sending a Text | |
def render_text_xml(data): | |
return """<?xml version="1.0" encoding="UTF-8"?> | |
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://api.callfire.com/service/xsd" xmlns:ns2="http://api.callfire.com/data"> | |
<env:Body> | |
<ns1:SendText> | |
<ns1:ToNumber>{to_number}</ns1:ToNumber> | |
<ns2:TextBroadcastConfig> | |
<ns2:FromNumber>{from_number}</ns2:FromNumber> | |
<ns2:Message>{message}</ns2:Message> | |
</ns2:TextBroadcastConfig> | |
</ns1:SendText> | |
</env:Body> | |
</env:Envelope> | |
""".format(**data) | |
data = { | |
'to_number': '1231231234', | |
'from_number': '1231231234', | |
'message': 'Hello world!', | |
} | |
message = render_text_xml(data) | |
client.service['TextServicePort'].SendText(__inject={'msg': message}) | |
### Sending a Call | |
def render_call_xml(data): | |
from xml.sax.saxutils import escape | |
data['dialplan_xml'] = escape(data['dialplan_xml']) | |
return """<?xml version="1.0" encoding="UTF-8"?> | |
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://api.callfire.com/service/xsd" xmlns:ns2="http://api.callfire.com/data"> | |
<env:Body> | |
<ns1:SendCall> | |
<ns1:ToNumber>{to_number}</ns1:ToNumber> | |
<ns2:IvrBroadcastConfig> | |
<ns2:FromNumber>{from_number}</ns2:FromNumber> | |
<ns2:RetryConfig> | |
<ns2:MaxAttempts>4</ns2:MaxAttempts> | |
<ns2:MinutesBetweenAttempts>120</ns2:MinutesBetweenAttempts> | |
<ns2:RetryResults>BUSY NO_ANS</ns2:RetryResults> | |
</ns2:RetryConfig> | |
<ns2:DialplanXml>{dialplan_xml}</ns2:DialplanXml> | |
</ns2:IvrBroadcastConfig> | |
</ns1:SendCall> | |
</env:Body> | |
</env:Envelope> | |
""".format(**data) | |
data = { | |
'to_number': '1231231234', | |
'from_number': '1231231234', | |
'dialplan_xml': """ | |
<dialplan name="Root"> | |
<play type="callfireid">163605001</play> | |
<menu maxDigits="1" timeout="10000"> | |
<play name="number" type="callfireid">163606001</play> | |
<keypress pressed="1"> | |
<play type="callfireid">163607001</play> | |
<goto>number</goto> | |
</keypress> | |
</menu> | |
</dialplan>""" | |
} | |
message = render_call_xml(data) | |
client.service['CallServicePort'].SendCall(__inject={'msg': message}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment