Copyright 2008 Tagga Media Inc All rights Reserved
When a user texts a message to a developer's keyword, we will post the text, tagg, and transaction ID to that developer's callback URL (set here). The developer will be able to make a decision based on the text and send a response to the user using the same transaction ID.
Order of Events:
Callback URL (tagga posts to this URL):
This is developer specified on the API Account Page.
POST URL (developer posts to this URL):
http://tagga.com/api/response/
Restrictions:
Response:
An XML response is returned and details a unique transaction ID, response code, and response message. You are responsible for checking the response message and acting appropriately.
// get the parameters that tagga has posted
$transactionId = $_POST['transaction_id'];
$tagg = $_POST['tagg'];
$message = $_POST['message'];
// this is where you would handle the incoming message
// and determine how to respond
$postdata = http_build_query(
array(
'apikey' => 'abc123', // put your API key here
'passkey' => '321cba', // put your API password key here
'tagg' => $tagg, // the tagg you have reserved for this application
'transaction_id' => $transactionId, // Transaction ID, to link response to original request.
'message' => 'This is your response to the user based on what they sent to you.'
)
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$response = file_get_contents(
'http://tagga.com/api/response/',
false,
$context
);
// handle the response message
import urllib
import cgi
# get the parameters that tagga has posted
form = cgi.FieldStorage()
transaction_id = form['transaction_id'].value
tagg = form['tagg'].value
message = form['message'].value
# this is where you would handle the incoming message
# and determine how to respond
apikey = u'abc123' # put your API key here
passkey = u'321cba' # put your API password key here
message = u'This is your response to the user based on what they sent to you.'
postdata = urllib.urlencode({'apikey': apikey, 'passkey': passkey, 'tagg': tagg, 'transaction_id': transaction_id, 'message': message})
response = urllib.urlopen('http://tagga.com/api/response/', postdata)
# handle the response message
// this example assumes that this code is within the doGet()
// function of a class that extends HttpServlet
try {
String transactionId = req.getParameter("transaction_id");
String tagg = req.getParameter("tagg");
String message = req.getParameter("message");
// this is where you would handle the incoming message
// and determine how to respond
String postdata = URLEncoder.encode("apikey", "UTF-8") + "=" + URLEncoder.encode("abc123", "UTF-8");
postdata += "&" + URLEncoder.encode("passkey", "UTF-8") + "=" + URLEncoder.encode("321cba", "UTF-8");
postdata += "&" + URLEncoder.encode("tagg", "UTF-8") + "=" + URLEncoder.encode(tagg, "UTF-8");
postdata += "&" + URLEncoder.encode("transaction_id", "UTF-8") + "=" + URLEncoder.encode(transactionId, "UTF-8");
postdata += "&" + URLEncoder.encode("message", "UTF-8") + "=" + URLEncoder.encode("This is your response to the user based on what they sent to you.", "UTF-8");
// Send data
URL url = new URL("http://tagga.com/api/response/");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(postdata);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
// handle the response here
wr.close();
rd.close();
} catch(Exception exc) {
// handle any exceptions
}
<?xml version="1.0" encoding="UTF-8"?>
<TaggaResponse version="1.0">
<TransactionID>100</TransactionID>
<ReturnCode>0</ReturnCode>
<Message>Success - API function call successful</Message>
</TaggaResponse>
<?xml version="1.0" encoding="UTF-8"?>
<TaggaResponse version="1.0">
<TransactionID>101</TransactionID>
<ReturnCode>20</ReturnCode>
<Message>Transaction Timeout - Developer did not respond to initial request soon enough</Message>
</TaggaResponse>
0: Success - API function call successful
1: Invalid Recipient - Not on allowed recipient list
2: Authentication Failed - apikey and passkey not valid
3: Incomplete API Call - Not all required parameters passed in
5: Message Length Invalid - Message text must be between 0 and 100 characters (140 if paid) for the latin character set, and 0 and 50 (70 if paid) for all others
6: Invalid Input - Some or all of the required parameters are invalid
7: Unknown Remote Address - This IP address is not allowed
8: Unknown tagg - Input tagg cannot be found
18: No Valid Payment Found - Campaign not created or message not sent, no valid payment found
19: Invalid Transaction - Transaction does not exist or was already responded to
20: Transaction Timeout - Developer did not respond to initial request soon enough