Created
November 6, 2010 19:09
-
-
Save mheadd/665633 to your computer and use it in GitHub Desktop.
A simple C# console application to initiate SMS and Phone messages with Tropo
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
using System; | |
using System.Collections.Generic; | |
using System.Web; | |
using System.Xml; | |
using TropoCSharp.Structs; | |
using TropoCSharp.Tropo; | |
namespace OutboundTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// The voice and messaging tokens provisioned when your Tropo application is set up. | |
string textToken = "enter-your-messaging-token-here"; | |
string voiceToken = "enter-your-voice-token-here"; | |
// A collection to hold the parameters we want to send to the Tropo Session API. | |
IDictionary<string, string> parameters = new Dictionary<String, String>(); | |
// Enter a phone number to send a call or SMS message to here. | |
parameters.Add("sendToNumber", "1112223333"); | |
// Set the number the message will come from. | |
parameters.Add("fromNumber", "4445556666"); | |
// Select the channel you want to use via the Channel struct. | |
string channel = Channel.Voice; | |
parameters.Add("channel", channel); | |
// Message is sent as a query string parameter, make sure it is properly encoded. | |
parameters.Add("msg", HttpUtility.UrlEncode("What do you know?")); | |
// Add a customer name to use as part of the message. | |
parameters.Add("customerName", HttpUtility.UrlEncode("Joe")); | |
// Instantiate a new instance of the Tropo object. | |
Tropo tropo = new Tropo(); | |
// Create an XML doc to hold the response from the Tropo Session API. | |
XmlDocument doc = new XmlDocument(); | |
// Set the token to use. | |
string token = channel == Channel.Text ? textToken : voiceToken; | |
// Load the XML document with the return value of the CreateSession() method call. | |
doc.Load(tropo.CreateSession(token, parameters)); | |
// Display the results in the console. | |
Console.WriteLine("Result: " + doc.SelectSingleNode("session/success").InnerText.ToUpper()); | |
Console.WriteLine("Token: " + doc.SelectSingleNode("session/token").InnerText); | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment