// Example: Opn up the full conversations page in single-sign-on
        public static void OpenSingleSignOnConversationsPage()
        {
            var client = new StagingRestClient();

            try
            {
                // if you already have the user's authorization token, you can use it, like this:
                // client.SetAccessToken("pass in the token here");

                // or prompt the user for their Text-Em-All username/password
                client.SetAccessTokenByPromptingForLogin();

                // get single-sign-on URL for conversations
                var urlToOpen = client.GetConversationsPageUrl();

                // open browser (windows OS)
                Process.Start(new ProcessStartInfo("cmd", $"/c start {urlToOpen}"));
            }
            catch (Exception exception)
            {
                Console.WriteLine($"There was an error: {exception}");
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }
        // Example: Send a conversation text message
        //
        // Note: A message to a single contact sent immediately
        public static void SendTextMessage()
        {
            var client = new StagingRestClient();

            try
            {
                // if you already have the user's authorization token, you can use it, like this:
                // client.SetAccessToken("pass in the token here");

                // or prompt the user for their Text-Em-All username/password
                client.SetAccessTokenByPromptingForLogin();

                // enter a phone number to text
                // e.g. your own
                Console.Write($"Please enter a phone number to text: ");
                var phoneNumber = Console.ReadLine();

                // enter a text to send
                // please make it not spammy or salesy
                Console.Write($"Please enter a text message to send: ");
                var text = Console.ReadLine();

                // if you already have the ID stored for the toll free text-number
                // that you want to send the message out on (e.g. 18885551234), you can use that

                // or you can look up one that the user has access to:
                var textNumbers = client.Get <Feed <TextNumber> >("/v1/textnumbers");
                var textNumber  = textNumbers.Items.FirstOrDefault();

                if (textNumber == null)
                {
                    throw new Exception("The user does not have a toll free text number set up yet.");
                }

                var textMessageToSend = new TextMessage
                {
                    Message = text,
                    Contact = new Person {
                        PrimaryPhone = phoneNumber
                    }
                };

                var conversation = new TextConversation
                {
                    TextNumberID = textNumber.TextNumberID,
                    LastMessage  = textMessageToSend
                };

                // create broadcast
                var result = client.Post("/v1/conversations", conversation);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"There was an error: {exception}");
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }
Пример #3
0
        // Example: Send a voice broadcast using text to speech
        //
        // Note: Although a broadcast can go to as many recipients as you need
        //       in this example, we only prompt for one phone number
        public static void CreateTextToSpeechVoiceBroadcast()
        {
            var client = new StagingRestClient();

            try
            {
                // if you already have the user's authorization token, you can use it, like this:
                // client.SetAccessToken("pass in the token here");

                // or prompt the user for their Text-Em-All username/password
                client.SetAccessTokenByPromptingForLogin();

                // enter a phone number to call
                // e.g. your own
                Console.Write($"Please enter a phone number to call: ");
                var phoneNumber = Console.ReadLine();

                // enter a text to turn into text-to-speech
                // e.g. Hi everyone! This is my first test. Say 11 12 13 14 15 16 17 18 19 20. Goodbye!
                Console.Write($"Please enter a longer than 10 seconds text to speech message to play: ");
                var textToSpeech = Console.ReadLine();

                var broadcast = new Broadcast
                {
                    BroadcastName           = "Test broadcast",
                    BroadcastType           = "Announcement",
                    PrimaryPhoneNumbersOnly = true,

                    // contacts
                    Contacts = new List <Person>
                    {
                        new Person {
                            PrimaryPhone = phoneNumber
                        },
                        // add additional contacts if needed
                        // new Person { PrimaryPhone = phoneNumber, FirstName = "Optional", LastName = "Optional", Notes = "Optional" }
                    },

                    // audio
                    Audio = new Audio
                    {
                        TextToSpeech = true,
                        Text         = textToSpeech
                    }
                };

                // create broadcast
                var result = client.Post("/v1/broadcasts", broadcast);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"There was an error: {exception}");
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }
Пример #4
0
        // Example: Send a text broadcast
        //
        // Note: Although a broadcast can go to as many recipients as you need
        //       in this example, we only prompt for one phone number
        public static void CreateTextBroadcast()
        {
            var client = new StagingRestClient();

            try
            {
                // if you already have the user's authorization token, you can use it, like this:
                // client.SetAccessToken("pass in the token here");

                // or prompt the user for their Text-Em-All username/password
                client.SetAccessTokenByPromptingForLogin();

                // enter a phone number to text
                // e.g. your own
                Console.Write($"Please enter a phone number to text: ");
                var phoneNumber = Console.ReadLine();

                // enter a text to send
                // please make it not spammy or salesy
                Console.Write($"Please enter a text message to send: ");
                var text = Console.ReadLine();

                var broadcast = new Broadcast
                {
                    BroadcastName           = "Test broadcast",
                    BroadcastType           = "SMS",
                    PrimaryPhoneNumbersOnly = true,

                    // contacts
                    Contacts = new List <Person>
                    {
                        new Person {
                            PrimaryPhone = phoneNumber
                        },
                        // add additional contacts if needed
                        // new Person { PrimaryPhone = phoneNumber, FirstName = "Optional", LastName = "Optional", Notes = "Optional" }
                    },

                    // message
                    TextMessage = text
                };

                // create broadcast
                var result = client.Post("/v1/broadcasts", broadcast);
            }
            catch (Exception exception)
            {
                Console.WriteLine($"There was an error: {exception}");
            }

            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }