コード例 #1
0
        public static async Task Run(
            [QueueTrigger("sms-outgoing-messages")]
            dynamic outgoingSms,
            TraceWriter log,
            ExecutionContext context)
        {
            currentContext = context;

            try
            {
                log.Info($"Received response from {outgoingSms?.recipient?.id}");

                string mobileNumber    = outgoingSms?.from?.id;
                string templateId      = Configuration.Get("NotifyTemplateId");
                var    personalization = new Dictionary <string, dynamic> {
                    { "message", outgoingSms?.messageReceived }
                };
                string reference   = outgoingSms?.conversation?.id;
                string smsSenderId = Configuration.Get("NotifySmsSenderId");

                SmsNotificationResponse sendSmsTask = await Task.Run(() => SendSms(
                                                                         mobileNumber,
                                                                         templateId,
                                                                         personalization,
                                                                         reference,
                                                                         smsSenderId));

                log.Info($"SendSmsMessage response: {sendSmsTask}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #2
0
ファイル: NotificationClient.cs プロジェクト: simbo1905/ACDPP
        public SmsNotificationResponse SendSms(String mobileNumber, String templateId, Dictionary <String, dynamic> personalisation = null, String clientReference = null)
        {
            JObject o = CreateRequestParams(templateId, personalisation, clientReference);

            o.AddFirst(new JProperty("phone_number", mobileNumber));

            String response = this.POST(SEND_SMS_NOTIFICATION_URL, o.ToString(Formatting.None));

            SmsNotificationResponse receipt = JsonConvert.DeserializeObject <SmsNotificationResponse>(response);

            return(receipt);
        }
        public void SendSmsNotificationGeneratesExpectedResponse()
        {
            Dictionary <string, dynamic> personalisation = new Dictionary <string, dynamic>
            {
                { "name", "someone" }
            };
            SmsNotificationResponse expectedResponse = JsonConvert.DeserializeObject <SmsNotificationResponse>(Constants.fakeSmsNotificationResponseJson);

            MockRequest(Constants.fakeSmsNotificationResponseJson);

            SmsNotificationResponse actualResponse = client.SendSms(Constants.fakePhoneNumber, Constants.fakeTemplateId, personalisation);

            Assert.IsTrue(expectedResponse.Equals(actualResponse));
        }
コード例 #4
0
        public async Task SendSmsNotificationGeneratesExpectedResponse()
        {
            Dictionary <string, dynamic> personalisation = new Dictionary <string, dynamic>
            {
                { "name", "someone" }
            };
            SmsNotificationResponse expectedResponse = JsonConvert.DeserializeObject <SmsNotificationResponse>(Constants.fakeSmsNotificationResponseJson);

            MockRequest(Constants.fakeSmsNotificationResponseJson);

            SmsNotificationResponse actualResponse = await client.SendSmsAsync(Constants.fakePhoneNumber, Constants.fakeTemplateId, personalisation);

            Assert.AreEqual(expectedResponse, actualResponse);
        }
        public async Task SendSmsTestWithPersonalisation()
        {
            Dictionary <String, dynamic> personalisation = new Dictionary <String, dynamic>
            {
                { "name", "someone" }
            };

            SmsNotificationResponse response =
                await this.client.SendSmsAsync(FUNCTIONAL_TEST_NUMBER, SMS_TEMPLATE_ID, personalisation, "sample-test-ref");

            this.smsNotificationId = response.id;
            Assert.IsNotNull(response);
            Assert.AreEqual(response.content.body, TEST_SMS_BODY);

            Assert.IsNotNull(response.reference);
            Assert.AreEqual(response.reference, "sample-test-ref");
        }
        public async Task SendSmsTestWithPersonalisationAndSmsSenderId()
        {
            Dictionary <String, dynamic> personalisation = new Dictionary <String, dynamic>
            {
                { "name", "someone" }
            };

            NotificationClient client_sending = new NotificationClient(NOTIFY_API_URL, API_SENDING_KEY);

            SmsNotificationResponse response =
                await client_sending.SendSmsAsync(FUNCTIONAL_TEST_NUMBER, SMS_TEMPLATE_ID, personalisation, "sample-test-ref", SMS_SENDER_ID);

            this.smsNotificationId = response.id;
            Assert.IsNotNull(response);
            Assert.AreEqual(response.content.body, TEST_SMS_BODY);

            Assert.IsNotNull(response.reference);
            Assert.AreEqual(response.reference, "sample-test-ref");
        }
        public void SendSmsNotificationGeneratesExpectedRequest()
        {
            Dictionary <string, dynamic> personalisation = new Dictionary <string, dynamic>
            {
                { "name", "someone" }
            };
            JObject expected = new JObject
            {
                { "phone_number", Constants.fakePhoneNumber },
                { "template_id", Constants.fakeTemplateId },
                { "personalisation", JObject.FromObject(personalisation) }
            };

            MockRequest(Constants.fakeSmsNotificationResponseJson,
                        client.SEND_SMS_NOTIFICATION_URL,
                        AssertValidRequest,
                        HttpMethod.Post,
                        AssertGetExpectedContent, expected.ToString(Formatting.None));

            SmsNotificationResponse response = client.SendSms(Constants.fakePhoneNumber, Constants.fakeTemplateId, personalisation);
        }