public void ConvertEmptyActivityWithCallbackData_Success()
        {
            var callbackData = new Dictionary <string, string>
            {
                { "BoolProperty", "true" },
                { "NumberProperty", "12" },
                { "StringProperty", "string" },
                { "DateProperty", DateTimeOffset.MinValue.ToString() }
            };

            _activity.AddInfobipCallbackData(callbackData);

            var messages = ToInfobipSmsConverter.Convert(_activity, TestOptions.Get());

            Assert.Empty(messages);
        }
        public void ConvertTextActivityWithCallbackDataAddedWithExtensionMethod_Success()
        {
            var callbackData = new Dictionary <string, string>
            {
                { "BoolProperty", "true" },
                { "NumberProperty", "12" },
                { "StringProperty", "string" },
                { "DateProperty", DateTimeOffset.MinValue.ToString() }
            };

            _activity.Text = "Activity with callback data";
            _activity.AddInfobipCallbackData(callbackData);

            var message = ToInfobipSmsConverter.Convert(_activity, TestOptions.Get()).Single();

            Assert.Equal(message.CallbackData, JsonConvert.SerializeObject(callbackData));
        }
        public void ConvertActivityWithSmsChannelIdToOmniSmsFailoverMessage()
        {
            _activity.Text      = "Test text";
            _activity.ChannelId = InfobipSmsConstants.ChannelName;

            var omniFailoverMessages = ToInfobipSmsConverter.Convert(_activity, TestOptions.Get());

            Assert.NotNull(omniFailoverMessages);
            Assert.Single(omniFailoverMessages);

            var omniFailoverMessage = omniFailoverMessages.First();

            Assert.Equal(omniFailoverMessage.ScenarioKey, TestOptions.SmsScenarioKey);
            CheckDestinations(omniFailoverMessage.Destinations);

            Assert.NotNull(omniFailoverMessage);
            Assert.NotNull(omniFailoverMessage.Sms);
        }
        /// <summary>
        /// Standard BotBuilder adapter method to send a message from the bot to the messaging API.
        /// </summary>
        /// <param name="turnContext">A TurnContext representing the current incoming message and environment.</param>
        /// <param name="activities">An array of outgoing activities to be sent back to the messaging API.</param>
        /// <param name="cancellationToken">A cancellation token for the task.</param>
        /// <returns>An array of <see cref="ResourceResponse"/> objects containing the IDs that Infobip assigned to the sent messages.</returns>
        public override async Task <ResourceResponse[]> SendActivitiesAsync(ITurnContext turnContext,
                                                                            Activity[] activities,
                                                                            CancellationToken cancellationToken)
        {
            var responses = new List <ResourceResponse>();

            foreach (var activity in activities)
            {
                if (activity.Type == ActivityTypes.Message)
                {
                    var messages         = ToInfobipSmsConverter.Convert(activity, _smsAdapterOptions);
                    var infobipResponses = new List <InfobipResponseMessage>();

                    foreach (var message in messages)
                    {
                        var currentResponse = await _infobipSmsClient.SendMessageAsync(message, cancellationToken).ConfigureAwait(false);

                        if (currentResponse == null)
                        {
                            continue;
                        }

                        _logger.Log(LogLevel.Debug,
                                    $"Received MT submit response: MessageId={currentResponse.MessageId}, " +
                                    $"Status={JsonConvert.SerializeObject(currentResponse.Status)}");

                        infobipResponses.Add(currentResponse);
                    }

                    responses.Add(new InfobipResourceResponse
                    {
                        Id               = string.Join("|", infobipResponses.Select(x => x.MessageId.ToString())),
                        ActivityId       = activity.Id,
                        ResponseMessages = infobipResponses
                    });
                }
            }

            return(responses.ToArray());
        }
        public void ConvertTextActivityToOmniFailoverMessage()
        {
            Activity activity = null;

            Assert.Throws <ArgumentNullException>(() => ToInfobipSmsConverter.Convert(activity, TestOptions.Get()));
        }
        public void ConvertActivityWithRecipient_ThrowException()
        {
            _activity.Recipient = null;

            Assert.Throws <ValidationException>(() => ToInfobipSmsConverter.Convert(_activity, TestOptions.Get()));
        }