static void Main(string[] args)
        {
            string token        = "your-voice-token-goes-here";
            string conferenceID = "my-test-conference";

            // An array of numbers to call and join to the conference.
            string[] numbersToCall = new string[] { "13034567890", "13034567891" };

            // SIP endpoint for a simple Tropo JavaScript app to play a message to the conference. See README file
            string conferenceTimer = "sip:[email protected]";

            // the length of time to wait before playing the conference message.
            int timer = 60000;

            // A collection to hold the parameters we want to send to the Tropo Session API.
            IDictionary <string, string> parameters = new Dictionary <String, String>();

            // 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();

            // Add the conferencce ID to the paramters collection.
            parameters.Add("conferenceID", conferenceID);

            foreach (string number in numbersToCall)
            {
                // Add the number to call to the parameters collection.
                parameters.Add("callToNumber", number);

                // Make API call.
                Console.WriteLine("Sending API request for: " + number);
                doc.Load(tropo.CreateSession(token, parameters));
                Console.WriteLine("Result: " + doc.SelectSingleNode("session/success").InnerText.ToUpper());
                Console.WriteLine("Token: " + doc.SelectSingleNode("session/token").InnerText);
                Console.WriteLine("=============================");

                // Remove the callToNumber key so we can reset in next loop.
                parameters.Remove("callToNumber");
            }

            // Sleep for x seconds.
            Thread.Sleep(timer);

            // Send reminder message to the conference.
            Console.WriteLine("Sending conference time reminder.");
            parameters.Add("callToNumber", conferenceTimer);
            doc.Load(tropo.CreateSession(token, parameters));
            Console.WriteLine("Result: " + doc.SelectSingleNode("session/success").InnerText.ToUpper());
            Console.WriteLine("Token: " + doc.SelectSingleNode("session/token").InnerText);
            Console.WriteLine("=============================");

            Console.Read();
        }
        private static NotificationResult SendSms(IEnumerable <string> to, string message)
        {
            // Create an XML doc to hold the response from the Tropo Session API.
            XmlDocument doc = new XmlDocument();

            // send
            foreach (var num in to)
            {
                // configure parameters
                Dictionary <string, string> map = new Dictionary <string, string> ();
                map.Add("sendToNumber", CommonUtils.ParseNumericString(num));
                map.Add("sendFromNumber", CommonUtils.ParseNumericString(Configuration.TropoFromNumber));
                map.Add("channel", Channel.Text);
                map.Add("network", Network.SMS);
                map.Add("msg", HttpUtility.UrlEncode(String.Join("", CommonUtils.RemoveAccentuation(message))));

                // create tropo instance
                var tropo = new Tropo();

                // Load the XML document with the return value of the CreateSession() method call.
                doc.Load(tropo.CreateSession(Configuration.TropoSmsToken, map));
            }
            // treat result
            if (String.IsNullOrEmpty(doc.InnerXml))
            {
                throw new Exception("Tropo operation failed");
            }
            return(new NotificationResult(true, doc.InnerXml));
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (StreamReader reader = new StreamReader(Request.InputStream))
            {
                // Get the JSON submitted from Tropo.
                string sessionJSON = TropoUtilities.parseJSON(reader);

                // Create a new instance of the Tropo class.
                Tropo tropo = new Tropo();

                // Create a new Session object and pass in the JSON submitted from Tropo.
                Session tropoSession = new Session(sessionJSON);
                string  smsReceived  = tropoSession.InitialText;

                // yu can do your business logic with smsReceived....
                //....
                //....

                // Create an XML doc to hold the response from the Tropo Session API.
                XmlDocument doc   = new XmlDocument();
                string      token = "6c48697670656858594b62704c62715358444e5a72744a794156715872656a66627a72464b7158626d58374"; // the app's voice token (app's url is SMSBusineessLogic.aspx)
                // A collection to hold the parameters we want to send to the Tropo Session API.
                IDictionary <string, string> parameters = new Dictionary <String, String>();

                parameters.Add("numberToDial", "+8613466549249");
                parameters.Add("textMessageBody", smsReceived);

                // Inintialized another application, here I just say the smsReceived to numberToDial
                doc.Load(tropo.CreateSession(token, parameters));
            }
        }
Example #4
0
        /// <summary>
        /// Creates a session for the Tropo Service
        /// </summary>
        public static void CreateSession()
        {
            Tropo inst = GetInstance();

            XmlDocument doc = new XmlDocument();

            string token = ConfigurationManager.AppSettings["Tropo.APIKey"];

            doc.Load(inst.CreateSession(token));

            string success  = doc.SelectSingleNode("session/success").InnerText.ToUpper();
            string tokenStr = doc.SelectSingleNode("session/token").InnerText;

            return;
        }
Example #5
0
        static void Main(string[] args)
        {
            // The voice and messaging tokens provisioned when your Tropo application is set up.
            string voiceToken     = "your-voice-token-here";
            string messagingToken = "your-messaging-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("numberToDial", "15551112222");

            // Enter a phone number to use as the caller ID.
            parameters.Add("sendFromNumber", "15551113333");

            // Select the channel you want to use via the Channel struct.
            string channel = Channel.Text;

            parameters.Add("channel", channel);

            string network = Network.SMS;

            parameters.Add("network", network);

            // Message is sent as a query string parameter, make sure it is properly encoded.
            parameters.Add("textMessageBody", HttpUtility.UrlEncode("This is a test message from C#."));

            // 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 ? messagingToken : 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();
        }
        private static NotificationResult SendCall(IEnumerable <string> to, string message)
        {
            // Create an XML doc to hold the response from the Tropo Session API.
            XmlDocument doc = new XmlDocument();

            // send
            foreach (var num in to)
            {
                // configure parameters
                Dictionary <string, string> map = new Dictionary <string, string> (StringComparer.Ordinal);
                map.Add("numberToDial", CommonUtils.ParseNumericString(num));

                switch (Configuration.TropoVoice)
                {
                case NotificationLanguage.en:
                    map.Add("voz", Voice.UsEnglishMale);
                    break;

                case NotificationLanguage.es:
                    map.Add("voz", Voice.CastilianSpanishMale);
                    break;

                case NotificationLanguage.pt:
                default:
                    //map.Add ("voz", Voice.PortugeseBrazilianMale); TODO: FIX PORTUGUESE BRAZILIAN LANGUAGE
                    break;
                }

                map.Add("msg", HttpUtility.UrlEncode(String.Join("", CommonUtils.RemoveAccentuation(message)), Encoding.GetEncoding("ISO-8859-1")));

                // create tropo instance
                var tropo = new Tropo();

                // Load the XML document with the return value of the CreateSession() method call.
                doc.Load(tropo.CreateSession(Configuration.TropoCallToken, map));
            }
            // treat result
            if (String.IsNullOrEmpty(doc.InnerXml))
            {
                throw new Exception("Tropo operation failed");
            }
            return(new NotificationResult(true, doc.InnerXml));
        }