public void SendText() { var recipient1 = new TextRecipient { Message = "msg", PhoneNumber = "12132212384" }; var recipient2 = new TextRecipient { Message = "msg", PhoneNumber = "12132212384" }; var recipients = new List<TextRecipient> { recipient1, recipient2 }; IList<CallfireApiClient.Api.CallsTexts.Model.Text> texts = Client.TextsApi.Send(recipients, null, "items(id,fromNumber,state)"); Console.WriteLine("Texts: " + texts); Assert.AreEqual(2, texts.Count); Assert.NotNull(texts[0].Id); Assert.IsNull(texts[0].CampaignId); Assert.IsTrue(StateType.READY == texts[0].State || StateType.FINISHED == texts[0].State); recipient1.Message = null; var request = new SendTextsRequest { Recipients = recipients, CampaignId = 7415135003, DefaultMessage = "DefaultLiveMessage", Fields = "items(id,fromNumber,state)" }; texts = Client.TextsApi.Send(request); CallfireApiClient.Api.CallsTexts.Model.Text text = Client.TextsApi.Get((long)texts[0].Id); Assert.AreEqual(text.Message, "DefaultLiveMessage"); }
/// <summary> /// Send texts to recipients through existing campaign, if null default campaign will be used /// Use the /texts API to quickly send individual texts.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 text 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<Text> Send(SendTextsRequest request) { Validate.NotBlank(request.Recipients.ToString(), "recipients cannot be blank"); var queryParams = ClientUtils.BuildQueryParams(request); return Client.Post<ListHolder<Text>>(TEXTS_PATH, request.Recipients, queryParams).Items; }
public void SendTextsUsingRequest() { string requestJson = GetJsonPayload("/callstexts/textsApi/request/sendTexts.json"); string responseJson = GetJsonPayload("/callstexts/textsApi/response/sendTexts.json"); var restRequest = MockRestResponse(responseJson); TextRecipient r1 = new TextRecipient { PhoneNumber = "12135551100", Message = "Hello World!" }; TextRecipient r2 = new TextRecipient { PhoneNumber = "12135551101", Message = "Testing 1 2 3" }; var request = new SendTextsRequest { Recipients = new List<TextRecipient> { r1, r2 }, CampaignId = 100, Fields = FIELDS, DefaultMessage = "defaultMessage" }; IList<CallfireApiClient.Api.CallsTexts.Model.Text> texts = Client.TextsApi.Send(request); Assert.That(Serializer.Serialize(new ListHolder<CallfireApiClient.Api.CallsTexts.Model.Text>(texts)), 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)); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("campaignId") && p.Value.Equals("100"))); Assert.That(restRequest.Value.Parameters, Has.Some.Matches<Parameter>(p => p.Name.Equals("defaultMessage") && p.Value.Equals("defaultMessage"))); }