Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created November 6, 2010 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheadd/665633 to your computer and use it in GitHub Desktop.
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
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