public void SendCallsUsingRequest() { string requestJson = GetJsonPayload("/callstexts/callsApi/request/sendCalls.json"); string responseJson = GetJsonPayload("/callstexts/callsApi/response/sendCalls.json"); var restRequest = MockRestResponse(responseJson); CallRecipient r1 = new CallRecipient { PhoneNumber = "12135551100", LiveMessage = "Why hello there!", TransferDigit = "1", TransferMessage = "testMessage", TransferNumber = "12135551101" }; CallRecipient r2 = new CallRecipient { PhoneNumber = "12135551101", LiveMessage = "And hello to you too." }; var request = new SendCallsRequest { Recipients = new List<CallRecipient> { r1, r2 }, CampaignId = 10, Fields = FIELDS, DefaultLiveMessage = "DefaultLiveMessage", DefaultMachineMessage = "DefaultMachineMessage", DefaultLiveMessageSoundId = 1, DefaultMachineMessageSoundId = 1, DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 }; IList<Call> calls = Client.CallsApi.Send(request); Assert.That(Serializer.Serialize(new ListHolder<Call>(calls)), Is.EqualTo(responseJson)); Assert.AreEqual(Method.POST, restRequest.Value.Method); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); calls = Client.CallsApi.Send(new List<CallRecipient> { r1, r2 }, 10, FIELDS); Assert.That(restRequest.Value.Resource, !Is.StringContaining("fields" + FIELDS)); Assert.That(restRequest.Value.Resource, !Is.StringContaining("campaignId=10")); Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultLiveMessage=DefaultLiveMessage")); Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultMachineMessage=DefaultMachineMessage")); Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultLiveMessageSoundId=1")); Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultMachineMessageSoundId=1")); Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultMachineMessageSoundId=1")); Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultVoice=FRENCHCANADIAN1")); }
public void SendCall() { var contacts = Client.ContactsApi.Find(new FindContactsRequest()); var recipient1 = new CallRecipient { ContactId = contacts.Items[0].Id, LiveMessage = "testMessage", TransferDigit = "1", TransferMessage = "transferTestMessage", TransferNumber = "14246525473" }; var recipient2 = new CallRecipient { ContactId = contacts.Items[0].Id, LiveMessage = "testMessage", TransferDigit = "1", TransferMessageSoundId = 1, TransferNumber = "14246525473" }; var recipients = new List<CallRecipient> { recipient1, recipient2 }; IList<Call> calls = Client.CallsApi.Send(recipients, null, "items(id,fromNumber,state)"); Console.WriteLine("Calls: " + calls); Assert.AreEqual(2, calls.Count); Assert.NotNull(calls[0].Id); Assert.IsNull(calls[0].CampaignId); Assert.AreEqual(StateType.READY, calls[0].State); var request = new SendCallsRequest { Recipients = recipients, CampaignId = 7373471003, Fields = "items(id, fromNumber, state, campaignId)", DefaultLiveMessage = "DefaultLiveMessage", DefaultMachineMessage = "DefaultMachineMessage", DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 }; calls = Client.CallsApi.Send(request); Assert.AreEqual(2, calls.Count); Assert.AreEqual(calls[0].CampaignId, 7373471003); request = new SendCallsRequest { Recipients = recipients, CampaignId = 7373471003, Fields = "items(id, fromNumber, state, campaignId)", DefaultLiveMessageSoundId = 1, DefaultMachineMessageSoundId = 1, DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 }; calls = Client.CallsApi.Send(request); Assert.AreEqual(2, calls.Count); }
/// <summary> /// Send calls to recipients through default campaign. /// Use the API to quickly send individual calls. /// A verified Caller ID and sufficient credits are required to make a call. /// </summary> /// <param name="request">request object with different fields to filter</param> /// <returns>list with created call objects</returns> /// <exception cref="BadRequestException"> in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception> /// <exception cref="UnauthorizedException"> in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception> /// <exception cref="AccessForbiddenException"> in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception> /// <exception cref="ResourceNotFoundException"> in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception> /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception> /// <exception cref="CallfireApiException"> in case HTTP response code is something different from codes listed above.</exception> /// <exception cref="CallfireClientException"> in case error has occurred in client.</exception> public IList<Call> Send(SendCallsRequest request) { Validate.NotBlank(request.Recipients.ToString(), "recipients cannot be blank"); var queryParams = ClientUtils.BuildQueryParams(request); return Client.Post<ListHolder<Call>>(CALLS_PATH, request.Recipients, queryParams).Items; }