Beispiel #1
0
        public void GetBroadcastTexts()
        {
            var broadcast = new TextBroadcast
            {
                Name       = "text_broadcast_1",
                Message    = "test_msg",
                Recipients = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "14246525473"
                    }
                }
            };
            var broadcastId = Client.TextBroadcastsApi.Create(broadcast, false);

            var request = new GetByIdRequest {
                Id = broadcastId.Id
            };
            var texts = Client.TextBroadcastsApi.GetTexts(request);

            Console.WriteLine(texts);
            Assert.That(texts.Items, Is.Not.Empty);

            long testBatchId = (long)texts.Items[0].BatchId;

            request = new GetBroadcastCallsTextsRequest {
                Id = broadcastId.Id, BatchId = testBatchId
            };
            texts = Client.TextBroadcastsApi.GetTexts(request);
            Assert.AreEqual(texts.Items[0].BatchId, testBatchId);
        }
Beispiel #2
0
        public void Create()
        {
            var requestJson  = GetJsonPayload("/campaigns/textBroadcastsApi/request/createTextBroadcast.json");
            var responseJson = GetJsonPayload("/campaigns/textBroadcastsApi/response/createTextBroadcast.json");
            var restRequest  = MockRestResponse(responseJson);

            var textBroadcast = new TextBroadcast
            {
                Name       = "Example API SMS",
                FromNumber = "19206596476",
                Message    = "Hello World!",
                Recipients = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "13233832214"
                    },
                    new TextRecipient {
                        PhoneNumber = "13233832215"
                    },
                },
                ResumeNextDay = true
            };
            var id = Client.TextBroadcastsApi.Create(textBroadcast, true, true);

            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.Some.Matches <Parameter>(p => p.Name.Equals("start") && p.Value.Equals("True")));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches <Parameter>(p => p.Name.Equals("strictValidation") && p.Value.Equals("True")));
        }
        /// <summary>
        /// Update broadcast
        /// </summary>
        /// <param name="broadcast">broadcast to update</param>
        /// <param name="strictValidation">apply strict validation for contacts</param>
        /// <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 void Update(TextBroadcast broadcast, bool?strictValidation = null)
        {
            Validate.NotNull(broadcast.Id, "broadcast.id cannot be null");
            var queryParams = ClientUtils.BuildQueryParams("strictValidation", strictValidation.ToString());

            Client.Put <object>(TB_ITEM_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, broadcast.Id.ToString()), broadcast, queryParams);
        }
Beispiel #4
0
        public void StartStopArchiveCampaign()
        {
            var broadcast = new TextBroadcast
            {
                Name       = "text_broadcast",
                Message    = "test_msg",
                Recipients = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "14246525473"
                    }
                }
            };

            ResourceId id = Client.TextBroadcastsApi.Create(broadcast, false);

            var campaign = Client.TextBroadcastsApi.Get(id.Id);

            Console.WriteLine(campaign);
            Assert.NotNull(campaign);
            // start
            Client.TextBroadcastsApi.Start((long)campaign.Id);
            campaign = Client.TextBroadcastsApi.Get((long)campaign.Id, "id,status");
            Assert.AreEqual(BroadcastStatus.RUNNING, campaign.Status);
            // stop
            Client.TextBroadcastsApi.Stop((long)campaign.Id);
            campaign = Client.TextBroadcastsApi.Get((long)campaign.Id, "id,status");
            Assert.AreEqual(BroadcastStatus.STOPPED, campaign.Status);
            // archive
            Client.TextBroadcastsApi.Archive((long)campaign.Id);
            campaign = Client.TextBroadcastsApi.Get((long)campaign.Id, "id,status");
            Assert.AreEqual(BroadcastStatus.ARCHIVED, campaign.Status);
        }
        /// <summary>
        /// Create a text broadcast campaign using the Text Broadcast API. A campaign can be created with
        /// no contacts and bare minimum configuration, but contacts will have to be added further on to use the campaign.
        /// If start set to true campaign starts immediately
        /// </summary>
        /// <param name="broadcast">text broadcast to create</param>
        /// <param name="start">if set to true then broadcast will start immediately, by default it set to false</param>
        /// <param name="strictValidation">apply strict validation for contacts</param>
        /// <returns>ResourceId object with id of created broadcast</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 Create(TextBroadcast broadcast, bool start = false, bool?strictValidation = null)
        {
            var queryParams = new List <KeyValuePair <string, object> >(2);

            ClientUtils.AddQueryParamIfSet("start", start.ToString(), queryParams);
            ClientUtils.AddQueryParamIfSet("strictValidation", strictValidation.ToString(), queryParams);
            return(Client.Post <ResourceId>(TB_PATH, broadcast, queryParams));
        }
Beispiel #6
0
        public void ToggleRecipientsStatus()
        {
            var broadcast = new TextBroadcast
            {
                Name = "text_broadcast",
                BigMessageStrategy = BigMessageStrategy.SEND_MULTIPLE,
                Message            = "test_msg",
                Recipients         = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "12132212384"
                    },
                    new TextRecipient {
                        PhoneNumber = "12132212385"
                    }
                }
            };
            var id = Client.TextBroadcastsApi.Create(broadcast, false, false);

            var getTextsRequest = new GetByIdRequest {
                Id = id.Id
            };
            var texts = Client.TextBroadcastsApi.GetTexts(getTextsRequest);

            Assert.That(texts.Items, Is.Not.Empty);
            foreach (Text c in texts.Items)
            {
                Assert.AreEqual(StateType.READY, c.State);
            }

            var recipients = new List <Recipient>
            {
                new Recipient {
                    PhoneNumber = "12132212384"
                },
                new Recipient {
                    PhoneNumber = "12132212385"
                }
            };

            Client.TextBroadcastsApi.ToggleRecipientsStatus(id.Id, recipients, false);

            texts = Client.TextBroadcastsApi.GetTexts(getTextsRequest);
            foreach (Text c in texts.Items)
            {
                Assert.AreEqual(StateType.DISABLED, c.State);
            }

            Client.TextBroadcastsApi.ToggleRecipientsStatus(id.Id, recipients, true);

            texts = Client.TextBroadcastsApi.GetTexts(getTextsRequest);
            foreach (Text c in texts.Items)
            {
                Assert.AreEqual(StateType.READY, c.State);
            }
        }
    public static void Main(string[] args)
    {
        var client    = new CallfireClient("api_login", "api_password");
        var broadcast = new TextBroadcast
        {
            Name = "Charity Campaign",
            // set validated Caller ID number.
            FromNumber = "19206596476",
            // attach custom labels if needed
            Labels = new List <string> {
                "charity", "id-10003"
            },
            // set message text
            Message = @"Hello {u_name} ...",
            // add new recipients
            Recipients = new List <TextRecipient>
            {
                new TextRecipient
                {
                    PhoneNumber = "13233834422",
                    // set custom recipient attributes, they are available only to a single Call/Text
                    //  action, do not confuse them with contact fields which are stored with contact
                    //  and are available to each Call/Text where contact is attached to
                    Attributes = new Dictionary <string, string>
                    {
                        { "u_name", "Alice" },
                        { "age", "30" }
                    }
                },
                new TextRecipient
                {
                    PhoneNumber = "13233834433",
                    Attributes  = new Dictionary <string, string>
                    {
                        { "u_name", "Mark" },
                        { "age", "45" }
                    }
                },
                new TextRecipient
                {
                    PhoneNumber = "13233834488",
                    // you can override a message set in broadcast for a particular recipient
                    Message    = "Hi ${u_name}, the megic number is ${magic_number}",
                    Attributes = new Dictionary <string, string>
                    {
                        { "u_name", "Jane" },
                        { "magic_number", "10" }
                    }
                }
            }
        };

        // create broadcast with 'start' argument = true to start campaign immediately
        var id = client.TextBroadcastsApi.Create(broadcast, true);
    }
        public void SendTexts(List <Person> personList, string message, string broadcastName)
        {
            List <CallfireApiClient.Api.CallsTexts.Model.TextRecipient> recipientList = personList.Select(x =>
                                                                                                          new CallfireApiClient.Api.CallsTexts.Model.TextRecipient()
            {
                PhoneNumber = x.HomePhone,
            }).ToList();

            var broadcast = new TextBroadcast()
            {
                Name       = broadcastName ?? "CRMRECRUIT Broadcast",
                Message    = message,
                Recipients = recipientList,
            };
            var id = this.CFClient.TextBroadcastsApi.Create(broadcast, true);
        }
Beispiel #9
0
        public void CrudOperations()
        {
            var broadcast = new TextBroadcast
            {
                Name = "text_broadcast",
                BigMessageStrategy   = BigMessageStrategy.SEND_MULTIPLE,
                Message              = "test_msg",
                LocalTimeRestriction = new LocalTimeRestriction
                {
                    BeginHour   = 10,
                    BeginMinute = 10,
                    EndHour     = 22,
                    EndMinute   = 0,
                    Enabled     = true
                },
                Recipients = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "14246525473"
                    },
                    new TextRecipient {
                        PhoneNumber = "12132041238"
                    }
                },
                ResumeNextDay = true
            };
            var id             = Client.TextBroadcastsApi.Create(broadcast, true, true);
            var savedBroadcast = Client.TextBroadcastsApi.Get(id.Id);

            Assert.AreEqual(broadcast.Name, savedBroadcast.Name);
            Assert.AreEqual(savedBroadcast.ResumeNextDay, true);
            savedBroadcast.Name          = "updated_name";
            savedBroadcast.ResumeNextDay = false;
            Client.TextBroadcastsApi.Update(savedBroadcast, true);

            var updatedBroadcast = Client.TextBroadcastsApi.Get(id.Id, "id,name");

            Assert.Null(updatedBroadcast.Status);
            Assert.NotNull(updatedBroadcast.Id);
            Assert.AreEqual(savedBroadcast.Name, updatedBroadcast.Name);
            Assert.AreEqual(savedBroadcast.ResumeNextDay, false);
        }
Beispiel #10
0
        public void Update()
        {
            var expectedJson = GetJsonPayload("/campaigns/textBroadcastsApi/request/updateTextBroadcast.json");
            var restRequest  = MockRestResponse(expectedJson);

            var textBroadcast = new TextBroadcast
            {
                Id            = 11,
                Name          = "Example API SMS updated",
                Message       = "a new test message",
                ResumeNextDay = true
            };

            Client.TextBroadcastsApi.Update(textBroadcast);

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

            Assert.AreEqual(requestBodyParam.Value, expectedJson);
            Assert.That(restRequest.Value.Resource, Is.StringEnding("/11"));
        }
Beispiel #11
0
        public void Update()
        {
            var expectedJson = GetJsonPayload("/campaigns/textBroadcastsApi/request/updateTextBroadcast.json");
            var restRequest  = MockRestResponse(expectedJson);

            var textBroadcast = new TextBroadcast
            {
                Id            = 11,
                Name          = "Example API SMS updated",
                Message       = "a new test message",
                ResumeNextDay = true,
            };

            Client.TextBroadcastsApi.Update(textBroadcast, true);

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

            Assert.AreEqual(Serializer.Serialize(requestBodyParam.Value), expectedJson);
            Assert.That(restRequest.Value.Resource, Does.EndWith("/11"));
            Assert.That(restRequest.Value.Parameters, Has.Some.Matches <Parameter>(p => p.Name.Equals("strictValidation") && p.Value.Equals("True")));
        }
Beispiel #12
0
        public void GetBroadcastStats()
        {
            var broadcast = new TextBroadcast
            {
                Name       = "text_broadcast_2",
                Message    = "test_msg",
                Recipients = new List <TextRecipient>
                {
                    new TextRecipient {
                        PhoneNumber = "12132041238"
                    }
                }
            };
            var broadcastId = Client.TextBroadcastsApi.Create(broadcast, true);

            var begin  = DateTime.Now.AddDays(-5d);
            var end    = DateTime.Now;
            var fields = "TotalOutboundCount,remainingOutboundCount";
            var stats  = Client.TextBroadcastsApi.GetStats(broadcastId.Id, fields, begin, end);

            Console.WriteLine(stats);
        }
 public static void Main(string[] args)
 {
     var           client    = new CallfireClient("api_login", "api_password");
     TextBroadcast broadcast = client.TextBroadcastsApi.Get(379506003, "name,status,labels");
 }
        /// <summary>
        /// Create a text broadcast campaign using the Text Broadcast API. A campaign can be created with
        /// no contacts and bare minimum configuration, but contacts will have to be added further on to use the campaign.
        /// If start set to true campaign starts immediately
        /// </summary>
        /// <param name="broadcast">text broadcast to create</param>
        /// <param name="start">if set to true then broadcast will start immediately, by default it set to false</param>
        /// <returns>ResourceId object with id of created broadcast</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 Create(TextBroadcast broadcast, bool start = false)
        {
            var queryParams = ClientUtils.BuildQueryParams("start", start.ToString());

            return(Client.Post <ResourceId>(TB_PATH, broadcast, queryParams));
        }
 /// <summary>
 /// Update broadcast
 /// </summary>
 /// <param name="broadcast">broadcast to update</param>
 /// <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 void Update(TextBroadcast broadcast)
 {
     Validate.NotNull(broadcast.Id, "broadcast.id cannot be null");
     Client.Put <object>(TB_ITEM_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, broadcast.Id.ToString()), broadcast);
 }