public static void Main(string[] args)
 {
     var client  = new CallfireClient("api_login", "api_password");
     var request = new AddBatchRequest
     {
         CampaignId = 11646003,
         Name       = "contact batch for text",
         Recipients = new List <Recipient>
         {
             new TextRecipient {
                 PhoneNumber = "12135551122"
             },
             new TextRecipient {
                 PhoneNumber = "12135553434"
             },
             new TextRecipient
             {
                 PhoneNumber = "12135558090",
                 Attributes  = new Dictionary <string, string>
                 {
                     { "custom_external_id", "30005044" },
                     { "custom_property_1", "value1" }
                 }
             }
         },
         //or you can add contacts from particular contact list
         //ContactListId = 70055003
         ScrubDuplicates = true
     };
     var resourceId = client.TextBroadcastsApi.AddBatch(request);
 }
Beispiel #2
0
        public void AddBatch()
        {
            var requestJson  = GetJsonPayload("/campaigns/callBroadcastsApi/request/addBatch.json");
            var responseJson = GetJsonPayload("/campaigns/callBroadcastsApi/response/addBatch.json");
            var restRequest  = MockRestResponse(responseJson);

            var request = new AddBatchRequest
            {
                CampaignId = 15,
                Name       = "batch name",
                Recipients = new List <Recipient>
                {
                    new Recipient {
                        PhoneNumber = "12135551100"
                    },
                    new Recipient {
                        PhoneNumber = "12135551101"
                    },
                }
            };
            var id = Client.CallBroadcastsApi.AddBatch(request);

            Assert.That(Serializer.Serialize(id), 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.No.Some.Matches <Parameter>(p => p.Name.Equals("campaignId")));
            Assert.That(restRequest.Value.Resource, Is.StringEnding("/15/batches"));
        }
Beispiel #3
0
        public void AddBatch()
        {
            var requestJson  = GetJsonPayload("/campaigns/textBroadcastsApi/request/addBatch.json");
            var responseJson = GetJsonPayload("/campaigns/textBroadcastsApi/response/addBatch.json");
            var restRequest  = MockRestResponse(responseJson);

            var request = new AddBatchRequest
            {
                CampaignId      = 15,
                Name            = "contact batch for text",
                ScrubDuplicates = true,
                Recipients      = new List <Recipient>
                {
                    new TextRecipient {
                        PhoneNumber = "12135551122"
                    },
                    new TextRecipient {
                        PhoneNumber = "12135551123"
                    },
                },
                StrictValidation = true
            };
            var id = Client.TextBroadcastsApi.AddBatch(request);

            Assert.That(Serializer.Serialize(id), Is.EqualTo(responseJson));

            Assert.AreEqual(Method.POST, restRequest.Value.Method);
            var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);

            Assert.That(Serializer.Serialize(requestBodyParam.Value), Is.EqualTo(requestJson));
            Assert.That(restRequest.Value.Parameters, Has.No.Some.Matches <Parameter>(p => p.Name.Equals("campaignId")));
            Assert.That(restRequest.Value.Resource, Does.EndWith("/15/batches"));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches <Parameter>(p => p.Name.Equals("strictValidation") && p.Value.Equals("True")));
        }
        /// <summary>
        /// Add batch to text broadcast.
        /// The add batch API allows the user to add additional batches to an already created text broadcast
        /// campaign. The added batch will go through the CallFire validation process, unlike in the
        /// recipients version of this API. Because of this, use the scrubDuplicates flag to remove duplicates
        /// from your batch. Batches may be added as a contact list id, a list of contact ids, or a list of numbers.
        /// </summary>
        /// <param name="request">request with contacts</param>
        /// <returns>id of created batch</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 ResourceId AddBatch(AddBatchRequest request)
        {
            String path        = TB_ITEM_BATCHES_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.CampaignId.ToString());
            var    queryParams = ClientUtils.BuildQueryParams("strictValidation", request.StrictValidation.ToString());

            return(Client.Post <ResourceId>(path, request, queryParams));
        }
        public void AddRecipientsAndAddRemoveBatches()
        {
            var findRequest = new FindBroadcastsRequest
            {
                Name  = "updated_name",
                Limit = 1
            };
            var broadcasts = Client.CallBroadcastsApi.Find(findRequest);

            Console.WriteLine(broadcasts);
            Assert.That(broadcasts.Items, Is.Not.Empty);
            var id = broadcasts.Items[0].Id;

            var calls = Client.CallBroadcastsApi.AddRecipients((long)id, new List <Recipient>
            {
                new Recipient {
                    PhoneNumber = "12132212384"
                },
                new Recipient {
                    PhoneNumber = "12132212385"
                }
            });

            Console.WriteLine(calls);
            Assert.AreEqual(2, calls.Count);

            // get batches
            var getBatchesRequest = new GetByIdRequest {
                Id = id
            };
            var batches = Client.CallBroadcastsApi.GetBatches(getBatchesRequest);

            Console.WriteLine(batches);

            // add batch
            var addBatchRequest = new AddBatchRequest
            {
                CampaignId = (long)id,
                Name       = "new_batch",
                Recipients = new List <Recipient>
                {
                    new Recipient {
                        PhoneNumber = "12132212384"
                    },
                    new Recipient {
                        PhoneNumber = "12132212384"
                    }
                }
            };

            Client.CallBroadcastsApi.AddBatch(addBatchRequest);

            var updatedBatches = Client.CallBroadcastsApi.GetBatches(getBatchesRequest);

            Console.WriteLine(batches);
            Assert.AreEqual(batches.Items.Count + 1, updatedBatches.Items.Count);
        }
        public void AddRecipientsAndAddRemoveBatches()
        {
            var findRequest = new FindBroadcastsRequest
            {
                Name  = "updated_name",
                Limit = 1
            };
            var broadcasts = Client.CallBroadcastsApi.Find(findRequest);

            System.Console.WriteLine(broadcasts);
            Assert.That(broadcasts.Items, Is.Not.Empty);
            var id = broadcasts.Items[0].Id;

            var calls = Client.CallBroadcastsApi.AddRecipients((long)id, new List <Recipient>
            {
                new Recipient {
                    PhoneNumber = "12132212384"
                },
                new Recipient {
                    PhoneNumber = "12132212385"
                }
            }, null, true);

            System.Console.WriteLine(calls);
            Assert.AreEqual(2, calls.Count);

            // get batches
            var getBatchesRequest = new GetByIdRequest {
                Id = id
            };
            var batches = Client.CallBroadcastsApi.GetBatches(getBatchesRequest);

            System.Console.WriteLine(batches);

            // add batch
            var addBatchRequest = new AddBatchRequest
            {
                CampaignId = (long)id,
                Name       = "new_batch",
                Recipients = new List <Recipient>
                {
                    new Recipient {
                        PhoneNumber = "12132212386"
                    },
                    new Recipient {
                        PhoneNumber = "12132212387"
                    }
                },
                StrictValidation = true
            };
            ResourceId addedBatchId = Client.CallBroadcastsApi.AddBatch(addBatchRequest);

            var addedBatch = Client.BatchesApi.Get(addedBatchId.Id);

            Assert.AreEqual(addedBatch.BroadcastId, id);
        }
Beispiel #7
0
 public static void Main(string[] args)
 {
     var client  = new CallfireClient("api_login", "api_password");
     var request = new AddBatchRequest
     {
         // your existing campaign id, you can get it via find() operation
         CampaignId = 11646003,
         Name       = "Contacts Batch 1",
         // id of contact list that you have added on previous step
         ContactListId   = 300555001,
         ScrubDuplicates = true
     };
     var id = client.CallBroadcastsApi.AddBatch(request);
 }
        /// <summary>
        /// Add batch to text broadcast.
        /// The add batch API allows the user to add additional batches to an already created text broadcast
        /// campaign. The added batch will go through the CallFire validation process, unlike in the
        /// recipients version of this API. Because of this, use the scrubDuplicates flag to remove duplicates
        /// from your batch. Batches may be added as a contact list id, a list of contact ids, or a list of numbers.
        /// </summary>
        /// <param name="request">request with contacts</param>
        /// <returns>id of created batch</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 ResourceId AddBatch(AddBatchRequest request)
        {
            String path = TB_ITEM_BATCHES_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.CampaignId.ToString());

            return(Client.Post <ResourceId>(path, request));
        }
Beispiel #9
0
        public void AddRecipientsAndAddRemoveBatches()
        {
            var findRequest = new FindBroadcastsRequest
            {
                Name  = "updated_name",
                Limit = 1
            };
            var broadcasts = Client.TextBroadcastsApi.Find(findRequest);

            Console.WriteLine(broadcasts);
            Assert.That(broadcasts.Items, Is.Not.Empty);
            var id = broadcasts.Items[0].Id;

            // add recipients
            var recipients = new List <TextRecipient>
            {
                new TextRecipient {
                    PhoneNumber = "14246525473"
                },
                new TextRecipient {
                    PhoneNumber = "12132041238"
                }
            };
            var texts = Client.TextBroadcastsApi.AddRecipients((long)id, recipients, null, true);

            Console.WriteLine(texts);
            Assert.AreEqual(2, texts.Count);
            Assert.That(texts[0].Message, Does.StartWith("test_msg"));

            // get batches
            var getBatchesRequest = new GetByIdRequest {
                Id = id
            };
            var batches = Client.TextBroadcastsApi.GetBatches(getBatchesRequest);

            Console.WriteLine(batches);

            // add batch
            var addBatchRequest = new AddBatchRequest
            {
                CampaignId = (long)id,
                Name       = "new_batch",
                Recipients = new List <Recipient>
                {
                    new TextRecipient {
                        PhoneNumber = "14246525473"
                    },
                    new TextRecipient {
                        PhoneNumber = "12132041238"
                    }
                },
                StrictValidation = true
            };
            ResourceId addedBatchId = Client.TextBroadcastsApi.AddBatch(addBatchRequest);

            var addedBatch = Client.BatchesApi.Get(addedBatchId.Id);

            Console.WriteLine(batches);
            Assert.AreEqual(addedBatch.BroadcastId, id);
            Assert.True((bool)addedBatch.Enabled);
            Assert.AreEqual(addBatchRequest.Name, addedBatch.Name);

            addedBatch.Enabled = false;
            Client.BatchesApi.Update(addedBatch);
            Batch updatedBatch = Client.BatchesApi.Get(addedBatchId.Id);

            Assert.False((bool)updatedBatch.Enabled);
        }