Exemple #1
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid   = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken    = "your_auth_token";
        const string workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        TwilioClient.Init(accountSid, authToken);

        var activity = ActivityResource.Create(
            workspaceSid, "NewAvailableActivity", true);

        Console.WriteLine(activity.FriendlyName);
    }
Exemple #2
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var activity = ActivityResource.Create(
            friendlyName: "FriendlyName",
            pathWorkspaceSid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );

        Console.WriteLine(activity.Sid);
    }
        public void TestCreateResponse()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();

            twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            twilioRestClient.Request(Arg.Any <Request>())
            .Returns(new Response(
                         System.Net.HttpStatusCode.Created,
                         "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"available\": true,\"date_created\": \"2014-05-14T10:50:02Z\",\"date_updated\": \"2014-05-14T23:26:06Z\",\"friendly_name\": \"New Activity\",\"sid\": \"WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"url\": \"https://taskrouter.twilio.com/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Activities/WAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"workspace_sid\": \"WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}"
                         ));

            var response = ActivityResource.Create("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "FriendlyName", client: twilioRestClient);

            Assert.NotNull(response);
        }
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid   = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken    = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string workspaceSid = "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        TwilioClient.Init(accountSid, authToken);

        var activity = ActivityResource.Create(
            workspaceSid, "NewAvailableActivity", true);

        Console.WriteLine(activity.FriendlyName);
    }
Exemple #5
0
    static void Main(string[] args)
    {
        // Find your Account Sid and Token at twilio.com/console
        // DANGER! This is insecure. See http://twil.io/secure
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken  = "your_auth_token";

        TwilioClient.Init(accountSid, authToken);

        var activity = ActivityResource.Create(
            available: true,
            friendlyName: "NewAvailableActivity",
            pathWorkspaceSid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
            );

        Console.WriteLine(activity.Sid);
    }
        public void TestCreateRequest()
        {
            var twilioRestClient = Substitute.For <ITwilioRestClient>();
            var request          = new Request(
                HttpMethod.Post,
                Twilio.Rest.Domain.Taskrouter,
                "/v1/Workspaces/WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Activities",
                ""
                );

            request.AddPostParam("FriendlyName", Serialize("FriendlyName"));
            twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content"));

            try
            {
                ActivityResource.Create("WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "FriendlyName", client: twilioRestClient);
                Assert.Fail("Expected TwilioException to be thrown for 500");
            }
            catch (ApiException) {}
            twilioRestClient.Received().Request(request);
        }
Exemple #7
0
        /// <summary>
        /// To run this application, the following is required:
        ///
        /// - API token key/secret from Account -> Developer -> API Tokens
        /// - A verified Phone Number UUID from Account -> Telephony -> Phone Numbers -> Edit (in the URI)
        /// - Fill in variables to run example
        /// </summary>
        /// <param name="args"></param>
        async static Task Main(string[] args)
        {
            var tokenKey    = "";
            var tokenSecret = "";

            // Set the Phone Number ID (e.g., GncieHvbCKfMYXmeycoWZm)
            var phoneNumberId = "";

            // Sample contact information to call
            var firstName   = "";
            var lastName    = "";
            var phoneNumber = ""; // In E.164 format (such as +1xxxxxxxxx)

            // Initialize SDK
            OmnigageClient.Init(tokenKey, tokenSecret);

            var engagement = new EngagementResource
            {
                Name      = "Example SMS Blast",
                Direction = "outbound"
            };
            await engagement.Create();

            var template = new TextTemplateResource
            {
                Name = "Text Template",
                Body = "Sample body"
            };
            await template.Create();

            var activity = new ActivityResource
            {
                Name         = "SMS Blast",
                Kind         = ActivityKind.Text,
                Engagement   = engagement,
                TextTemplate = template,
                PhoneNumber  = new PhoneNumberResource
                {
                    Id = phoneNumberId
                }
            };
            await activity.Create();

            var envelope = new EnvelopeResource
            {
                PhoneNumber = phoneNumber,
                Engagement  = engagement,
                Meta        = new Dictionary <string, string>
                {
                    { "first-name", firstName },
                    { "last-name", lastName }
                }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await Client.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
Exemple #8
0
        async public Task TestVoiceEngagement()
        {
            var mockHttp           = new MockHttpMessageHandler();
            var engagementResponse = File.ReadAllText("UnitTests/Serialized/ResourceTestsEngagementResponse.json");
            var activityResponse   = File.ReadAllText("UnitTests/Serialized/ResourceTestsActivityResponse.json");
            var triggerResponse    = File.ReadAllText("UnitTests/Serialized/ResourceTestsTriggerResponse.json");
            var envelopeRequest    = File.ReadAllText("UnitTests/Serialized/ResourceTestsEnvelopeBulkRequest.json");

            mockHttp.When(HttpMethod.Post, "http://localhost/api/engagements")
            .Respond(System.Net.HttpStatusCode.Created, "application/json", engagementResponse);
            mockHttp.When(HttpMethod.Post, "http://localhost/api/activities")
            .Respond(System.Net.HttpStatusCode.Created, "application/json", activityResponse);
            mockHttp.When(HttpMethod.Post, "http://localhost/api/triggers")
            .Respond(System.Net.HttpStatusCode.Created, "application/json", triggerResponse);

            var httpClient = mockHttp.ToHttpClient();

            OmnigageClient.Init("key", "secret", "http://localhost/api/", httpClient);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example";
            engagement.Direction = "outbound";
            engagement.Status    = "scheduled";

            await engagement.Create();

            Assert.AreEqual(engagement.Id, "1");
            Assert.AreEqual(engagement.ToString(), engagementResponse);

            ActivityResource activity = new ActivityResource();

            activity.Name       = "Voice Blast";
            activity.Kind       = "voice";
            activity.Engagement = engagement;
            activity.CallerId   = new CallerIdResource
            {
                Id = "yL9vQaWrSqg5W8EFEpE6xZ"
            };

            await activity.Create();

            Assert.AreEqual(activity.Id, "1");
            Assert.AreEqual(activity.Name, "Voice Blast");
            Assert.AreEqual(activity.Kind, "voice");

            TriggerResource trigger = new TriggerResource();

            trigger.Kind          = "play";
            trigger.OnEvent       = "voice-machine";
            trigger.Activity      = activity;
            trigger.VoiceTemplate = new VoiceTemplateResource
            {
                Id = "RaF56o2r58hTKT7AYS9doj"
            };

            await trigger.Create();

            Assert.AreEqual(trigger.Id, "1");
            Assert.AreEqual(trigger.Kind, "play");
            Assert.AreEqual(trigger.OnEvent, "voice-machine");

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.PhoneNumber = "+11111111111";
            envelope.Engagement  = engagement;
            envelope.Meta        = new Dictionary <string, string>
            {
                { "first-name", "Michael" },
                { "last-name", "Morgan" }
            };

            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            string envelopesPayload = EnvelopeResource.SerializeBulk(envelopes);

            Assert.AreEqual(envelopesPayload, envelopeRequest);
        }
        /// <summary>
        /// To run this application, the following is required:
        ///
        /// - API token key/secret from Account -> Developer -> API Tokens
        /// - Two audio files (either wav or mp3)
        /// - A Caller ID UUID from Account -> Telephony -> Caller IDs -> Edit (in the URI)
        /// </summary>
        /// <param name="args"></param>
        async static Task Main(string[] args)
        {
            string tokenKey    = "";
            string tokenSecret = "";

            // Set the Caller ID (e.g., yL9vQaWrSqg5W8EFEpE6xZ)
            string callerId = "";

            // Sample contact information to call
            string firstName   = "";
            string lastName    = "";
            string phoneNumber = ""; // In E.164 format with country code (e.g., +11235551234)

            // Audio path for when human is detected
            string audioFilePath1 = ""; // Full path to audio file (e.g., /Users/Shared/piano.wav on Mac)

            // Audio path for machine detection
            string audioFilePath2 = ""; // Full path to audio file (e.g., /Users/Shared/nimoy_spock.wav on Mac)

            // Initialize SDK
            OmnigageClient.Init(tokenKey, tokenSecret);

            var engagement = new EngagementResource();

            engagement.Name      = "Example Voice Blast";
            engagement.Direction = "outbound";
            await engagement.Create();

            var activity = new ActivityResource();

            activity.Name       = "Voice Blast";
            activity.Kind       = ActivityKind.Voice;
            activity.Engagement = engagement;
            activity.CallerId   = new CallerIdResource
            {
                Id = callerId
            };
            await activity.Create();

            var upload1 = new UploadResource
            {
                FilePath = audioFilePath1
            };
            await upload1.Create();

            var upload2 = new UploadResource
            {
                FilePath = audioFilePath2
            };
            await upload2.Create();

            var humanRecording = new VoiceTemplateResource();

            humanRecording.Name   = "Human Recording";
            humanRecording.Kind   = "audio";
            humanRecording.Upload = upload1;
            await humanRecording.Create();

            var machineRecording = new VoiceTemplateResource();

            machineRecording.Name   = "Machine Recording";
            machineRecording.Kind   = "audio";
            machineRecording.Upload = upload2;
            await machineRecording.Create();

            // Define human trigger
            var triggerHumanInstance = new TriggerResource();

            triggerHumanInstance.Kind          = TriggerKind.Play;
            triggerHumanInstance.OnEvent       = TriggerOnEvent.VoiceHuman;
            triggerHumanInstance.Activity      = activity;
            triggerHumanInstance.VoiceTemplate = humanRecording;
            await triggerHumanInstance.Create();

            // Define machine trigger
            var triggerMachineInstance = new TriggerResource();

            triggerMachineInstance.Kind          = TriggerKind.Play;
            triggerMachineInstance.OnEvent       = TriggerOnEvent.VoiceMachine;
            triggerMachineInstance.Activity      = activity;
            triggerMachineInstance.VoiceTemplate = machineRecording;
            await triggerMachineInstance.Create();

            var envelope = new EnvelopeResource();

            envelope.PhoneNumber = phoneNumber;
            envelope.Engagement  = engagement;
            envelope.Meta        = new Dictionary <string, string>
            {
                { "first-name", firstName },
                { "last-name", lastName }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await Client.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
        /// <summary>
        /// To run this application, the following is required:
        ///
        /// - API token key/secret from Account -> Developer -> API Tokens
        /// - A verified Email ID UUID from Account -> Email -> Email IDs -> Edit (in the URI)
        /// - Fill in variables to run example
        /// </summary>
        /// <param name="args"></param>
        async static Task Main(string[] args)
        {
            var tokenKey    = "";
            var tokenSecret = "";

            // Set the Email ID (e.g., NbXW9TCHax9zfAeDhaY2bG)
            var emailId = "";

            // Sample contact information to call
            var firstName    = "";
            var lastName     = "";
            var emailAddress = "";

            // Initialize SDK
            OmnigageClient.Init(tokenKey, tokenSecret);

            var engagement = new EngagementResource();

            engagement.Name      = "Example Email Blast";
            engagement.Direction = "outbound";
            await engagement.Create();

            var emailTemplate = new EmailTemplateResource();

            emailTemplate.Subject = "Ahoy";
            emailTemplate.Body    = "Sample body";

            await emailTemplate.Create();

            var activity = new ActivityResource();

            activity.Name          = "Email Blast";
            activity.Kind          = ActivityKind.Email;
            activity.Engagement    = engagement;
            activity.EmailTemplate = emailTemplate;
            activity.EmailId       = new EmailIdResource
            {
                Id = emailId
            };
            await activity.Create();

            var envelope = new EnvelopeResource();

            envelope.EmailAddress = emailAddress;
            envelope.Engagement   = engagement;
            envelope.Meta         = new Dictionary <string, string>
            {
                { "first-name", firstName },
                { "last-name", lastName }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await Client.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
        async public Task TestEmailVoiceEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementEmailVoiceTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Email Voice Blast (Voice Link)";
            engagement.Direction = "outbound";
            await engagement.Create();

            EmailTemplateResource emailTemplate = new EmailTemplateResource();

            emailTemplate.Subject = "Email Template";
            emailTemplate.Body    = "Email template with {{message-body}}.";
            await emailTemplate.Create();

            EmailMessageResource emailMessage = new EmailMessageResource();

            emailMessage.Subject = "Email Message";
            emailMessage.Body    = "Sample body";
            emailMessage.IsDraft = true;
            await emailMessage.Create();

            UploadResource upload1 = new UploadResource
            {
                FilePath = "Media/hello.mp3"
            };
            await upload1.Create();

            VoiceTemplateResource recording = new VoiceTemplateResource();

            recording.Name   = "Voice Link Recording";
            recording.Kind   = "audio";
            recording.Upload = upload1;
            await recording.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name = "Email Voice";
            activity.Kind = ActivityKind.EmailVoice;
            activity.CallBackPhoneNumber = "+11231231234";
            activity.Engagement          = engagement;
            activity.VoiceTemplate       = recording;
            activity.EmailTemplate       = emailTemplate;
            activity.EmailMessage        = emailMessage;
            activity.EmailId             = new EmailIdResource
            {
                Id = "NbXW9TCHax9zfAeDhaY2bG"
            };
            await activity.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.EmailAddress = "*****@*****.**";
            envelope.Engagement   = engagement;
            envelope.Meta         = new Dictionary <string, string>
            {
                { "first-name", "Omnigage" },
                { "last-name", "Demo" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await OmnigageClient.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
        async public Task TestTextEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementTextTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Text Blast";
            engagement.Direction = "outbound";

            await engagement.Create();

            TextTemplateResource textTemplate = new TextTemplateResource();

            textTemplate.Name = "Text Template";
            textTemplate.Body = "Sample body";

            await textTemplate.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name         = "Text Blast";
            activity.Kind         = ActivityKind.Text;
            activity.Engagement   = engagement;
            activity.TextTemplate = textTemplate;
            activity.PhoneNumber  = new PhoneNumberResource
            {
                Id = "GncieHvbCKfMYXmeycoWZm"
            };

            await activity.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.PhoneNumber = "+14076413749";
            envelope.Engagement  = engagement;
            envelope.Meta        = new Dictionary <string, string>
            {
                { "first-name", "Omnigage" },
                { "last-name", "Demo" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await Client.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
        async public Task TestVoiceEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Voice Blast";
            engagement.Direction = "outbound";

            await engagement.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name       = "Voice Blast";
            activity.Kind       = ActivityKind.Voice;
            activity.Engagement = engagement;
            activity.CallerId   = new CallerIdResource
            {
                Id = "yL9vQaWrSqg5W8EFEpE6xZ"
            };

            await activity.Create();

            UploadResource upload1 = new UploadResource
            {
                FilePath = "Media/hello.mp3"
            };
            await upload1.Create();

            UploadResource upload2 = new UploadResource
            {
                FilePath = "Media/you-have-new-mail-waiting.wav"
            };
            await upload2.Create();

            VoiceTemplateResource humanRecording = new VoiceTemplateResource();

            humanRecording.Name   = "Human Recording";
            humanRecording.Kind   = "audio";
            humanRecording.Upload = upload1;
            await humanRecording.Create();

            VoiceTemplateResource machineRecording = new VoiceTemplateResource();

            machineRecording.Name   = "Machine Recording";
            machineRecording.Kind   = "audio";
            machineRecording.Upload = upload2;
            await machineRecording.Create();

            // Define human trigger
            TriggerResource triggerHumanInstance = new TriggerResource();

            triggerHumanInstance.Kind          = TriggerKind.Play;
            triggerHumanInstance.OnEvent       = TriggerOnEvent.VoiceHuman;
            triggerHumanInstance.Activity      = activity;
            triggerHumanInstance.VoiceTemplate = humanRecording;
            await triggerHumanInstance.Create();

            // Define machine trigger
            TriggerResource triggerMachineInstance = new TriggerResource();

            triggerMachineInstance.Kind          = TriggerKind.Play;
            triggerMachineInstance.OnEvent       = TriggerOnEvent.VoiceMachine;
            triggerMachineInstance.Activity      = activity;
            triggerMachineInstance.VoiceTemplate = machineRecording;
            await triggerMachineInstance.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.PhoneNumber = "+18332676094";
            envelope.Engagement  = engagement;
            envelope.Meta        = new Dictionary <string, string>
            {
                { "first-name", "Spectrum" },
                { "last-name", "Support" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await OmnigageClient.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }
        async public Task TestEmailEngagement()
        {
            var scotchMode = ScotchMode.Replaying;
            var client     = HttpClients.NewHttpClient("IntegrationTests/Cassettes/EngagementEmailTests.json", scotchMode);

            string tokenKey    = "key";
            string tokenSecret = "secret";
            string host        = "https://dvfoa3pu2rxx6.cloudfront.net/api/v1/";

            OmnigageClient.Init(tokenKey, tokenSecret, host, client);

            EngagementResource engagement = new EngagementResource();

            engagement.Name      = "Example Email Blast";
            engagement.Direction = "outbound";

            await engagement.Create();

            EmailTemplateResource emailTemplate = new EmailTemplateResource();

            emailTemplate.Subject = "Ahoy";
            emailTemplate.Body    = "Sample body";

            await emailTemplate.Create();

            ActivityResource activity = new ActivityResource();

            activity.Name          = "Email Blast";
            activity.Kind          = ActivityKind.Email;
            activity.Engagement    = engagement;
            activity.EmailTemplate = emailTemplate;
            activity.EmailId       = new EmailIdResource
            {
                Id = "NbXW9TCHax9zfAeDhaY2bG"
            };

            await activity.Create();

            EnvelopeResource envelope = new EnvelopeResource();

            envelope.EmailAddress = "*****@*****.**";
            envelope.Engagement   = engagement;
            envelope.Meta         = new Dictionary <string, string>
            {
                { "first-name", "Omnigage" },
                { "last-name", "Demo" }
            };

            // Push one or more envelopes into list
            List <EnvelopeResource> envelopes = new List <EnvelopeResource> {
            };

            envelopes.Add(envelope);

            // Populate engagement queue
            await OmnigageClient.PostBulkRequest("envelopes", EnvelopeResource.SerializeBulk(envelopes));

            // Schedule engagement for processing
            engagement.Status = "scheduled";
            await engagement.Update();
        }