Last active
April 17, 2016 12:22
-
-
Save ObjectIsAdvantag/928201e2b842d671c57faf2325e1dc1a to your computer and use it in GitHub Desktop.
Tropo outgoing POST application/json
This file contains hidden or 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
import json | |
import urllib2 | |
version = "v20160417 - 0720" | |
log( version ) | |
webhook = "http://requestb.in/zd4mlazd" | |
answer() | |
say( "Welcome to the python v" + version ) | |
# GET sample with Query Parameters | |
#response = urllib2.urlopen( webhook + "?input=hello" ) | |
# POST sample with application/x-www-form-urlencoded | |
# This urlencodes your data (that's why we need to import urllib at the top) | |
#data = { "input":"hello", "from":"[email protected]" } | |
#encoded = urllib.urlencode( data ) | |
#response = urllib2.urlopen( webhook, encoded ) | |
# POST sample with JSON payload | |
request = urllib2.Request( webhook ) | |
request.add_header( "Content-Type", "application/json" ) | |
data = { "input":"hello", "from":"[email protected]" } | |
response = urllib2.urlopen( request, json.dumps( data ) ) | |
if response : | |
say( "your answer has been posted" ) | |
else : | |
say( "I am sorry, Error occured while sending your answer" ) | |
say( "Thats all. Goodbye!" ) | |
hangup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment