public void TestCreateResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"api_version\": \"2010-04-01\",\"callback_method\": \"GET\",\"callback_url\": \"http://cap.com/streetfight\",\"current_value\": \"0\",\"date_created\": \"Sun, 06 Sep 2015 12:58:45 +0000\",\"date_fired\": null,\"date_updated\": \"Sun, 06 Sep 2015 12:58:45 +0000\",\"friendly_name\": \"raphael-cluster-1441544325.86\",\"recurring\": \"yearly\",\"sid\": \"UTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"trigger_by\": \"price\",\"trigger_value\": \"50\",\"uri\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Usage/Triggers/UTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"usage_category\": \"totalprice\",\"usage_record_uri\": \"/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Usage/Records?Category=totalprice\"}" )); var response = TriggerResource.Create(new Uri("https://example.com"), "triggerValue", TriggerResource.UsageCategoryEnum.AnsweringMachineDetection, client: twilioRestClient); Assert.NotNull(response); }
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"; TwilioClient.Init(accountSid, authToken); var callbackUrl = new Uri("http://www.example.com/"); const string triggerValue = "1000"; var trigger = TriggerResource.Create(callbackUrl, triggerValue, TriggerResource.UsageCategoryEnum.Sms); Console.WriteLine(trigger.Sid); }
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 trigger = TriggerResource.Create( callbackUrl: new Uri("https://example.com"), triggerValue: "TriggerValue", usageCategory: TriggerResource.UsageCategoryEnum.AnsweringMachineDetection ); Console.WriteLine(trigger.Sid); }
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"); TwilioClient.Init(accountSid, authToken); var callbackUrl = new Uri("http://www.example.com/"); const string triggerValue = "1000"; var trigger = TriggerResource.Create(callbackUrl, triggerValue, TriggerResource.UsageCategoryEnum.Sms); Console.WriteLine(trigger.Sid); }
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 trigger = TriggerResource.Create( callbackUrl: new Uri("https://example.com"), triggerValue: "triggerValue", usageCategory: TriggerResource.UsageCategoryEnum.AgentConference ); Console.WriteLine(trigger.Sid); }
public void TestCreateRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Post, Twilio.Rest.Domain.Api, "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Usage/Triggers.json", "" ); request.AddPostParam("CallbackUrl", Serialize(new Uri("https://example.com"))); request.AddPostParam("TriggerValue", Serialize("triggerValue")); request.AddPostParam("UsageCategory", Serialize(TriggerResource.UsageCategoryEnum.AnsweringMachineDetection)); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { TriggerResource.Create(new Uri("https://example.com"), "triggerValue", TriggerResource.UsageCategoryEnum.AnsweringMachineDetection, client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
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(); }
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(); }