public static void Send(SqlString phoneNumber, SqlString from, SqlString message)
    {
        // Set the channel options; optional step, comment out to use a local number to send from automatically
        var myChannelOptions = new SMSSendRequest.channelOptionsStruct();

        myChannelOptions.sms = new SMSSendRequest.smsChannelOptions()
        {
            from = from.Value, allowUnicode = true
        };

        // Send the messages
        var myRequest = new SMSSendRequest();

        myRequest.to             = new SMSSendRequest.toStruct(phoneNumber.Value);
        myRequest.body           = message.Value;
        myRequest.channelOptions = myChannelOptions;

        // Send it.
        SendSMS(myRequest);
    }
Ejemplo n.º 2
0
        static async Task Main(string[] args)
        {
            try
            {
                // Ensure we use later versions of TLS for security
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072 | (SecurityProtocolType)768;

                // Start the console
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("Dotdigital enterprise Communications API SMS send example");
                Console.ForegroundColor = ConsoleColor.White;

                string         input, mode = null;
                SMSSendRequest myRequest = null;

                // Ask the user what demo mode they want
                do
                {
                    Console.WriteLine("Send a `single` message or a `batch`, enter your choice now?");
                    input = Console.ReadLine().ToLower();
                    switch (input)
                    {
                    case "s":
                    case "single":
                        mode = "single";
                        Console.WriteLine("Performing a single send");
                        break;

                    case "b":
                    case "batch":
                        mode = "batch";
                        Console.WriteLine("Performing a batch send of {0} messages", BATCH_SIZE);
                        break;
                    }

                    if (!string.IsNullOrEmpty(mode))
                    {
                        break;
                    }
                } while (true);

                // Set the channel options; optional step, comment out to use a local number to send from automatically
                var myChannelOptions = new SMSSendRequest.channelOptionsStruct();
                myChannelOptions.sms = new SMSSendRequest.smsChannelOptions()
                {
                    from = "Example", allowUnicode = false
                };

                // Send the messages
                switch (mode)
                {
                case "single":
                    // Create an SMS request.
                    myRequest                = new SMSSendRequest();
                    myRequest.to             = new SMSSendRequest.toStruct(MOBILE_NUMBER);
                    myRequest.body           = "This is an SMS via Dotdigital Enterprise Communications API";
                    myRequest.channelOptions = myChannelOptions;

                    // Send it.
                    await SendSMS(myRequest);

                    break;

                case "batch":
                    // Create a couple of requests in an array to create a batch of requests
                    SMSSendRequest[] myBatch = new SMSSendRequest[BATCH_SIZE];

                    for (int i = 0; i < BATCH_SIZE; i++)
                    {
                        // Create a message send request
                        myRequest                = new SMSSendRequest();
                        myRequest.to             = new SMSSendRequest.toStruct(MOBILE_NUMBER);
                        myRequest.body           = "This is message " + i;
                        myRequest.channelOptions = myChannelOptions;

                        // Add to batch array
                        myBatch[i] = myRequest;
                    }

                    // Send them
                    await SendSMSBatch(myBatch);

                    break;
                }

                // All good
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("SMS sent successfully");
                Console.ForegroundColor = ConsoleColor.White;
            }
            catch (Exception ex)
            {
                // Error
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error: {0}", ex);
                Console.ForegroundColor = ConsoleColor.White;
            }

            // Wait
            Console.WriteLine("Press enter to continue...");
            Console.ReadLine();
        }