private void VerifyResultCoreProperties(InfobipSmsIncomingResult result, Activity activity, string fromId)
 {
     Assert.Equal(result.MessageId, activity.Id);
     Assert.Equal(fromId, activity.From.Id);
     Assert.Equal(result.To, activity.Recipient.Id);
     Assert.Equal(result.To, activity.Conversation.Id);
     Assert.Equal(result, activity.ChannelData);
     Assert.Equal(result.DoneAt, activity.Timestamp);
 }
Esempio n. 2
0
        public static Activity Convert(InfobipSmsIncomingResult result, string smsNumber)
        {
            var activity = CreateBaseDeliveryReportActivity(result);

            activity.ChannelId = InfobipSmsConstants.ChannelName;
            activity.From      = new ChannelAccount {
                Id = smsNumber
            };
            return(activity);
        }
        private static void HandleCallbackData(InfobipSmsIncomingResult response, Activity activity)
        {
            if (string.IsNullOrWhiteSpace(response.CallbackData))
            {
                return;
            }
            var serialized = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.CallbackData);

            activity.AddInfobipCallbackData(serialized);
        }
Esempio n. 4
0
        public static Activity Convert(InfobipSmsIncomingResult result)
        {
            var activity = ConvertToMessage(result);

            activity.ChannelId  = InfobipSmsConstants.ChannelName;
            activity.Text       = result.CleanText;
            activity.TextFormat = TextFormatTypes.Plain;

            return(activity);
        }
        private Activity ConvertToActivity(InfobipSmsIncomingResult response)
        {
            if (response.Error != null)
            {
                //error codes - https://dev-old.infobip.com/getting-started/response-status-and-error-codes
                if (response.Error.Id > 0)
                {
                    throw new Exception($"{response.Error.Name} {response.Error.Description}");
                }
            }

            if (response.IsDeliveryReport())
            {
                _logger.Log(LogLevel.Debug, $"Received DLR notification: MessageId={response.MessageId}, " +
                            $"DoneAt={response.DoneAt}, SentAt={response.SentAt}, Channel={response.Channel}");

                var activity = InfobipSmsDeliveryReportToActivity.Convert(response, _smsAdapterOptions.InfobipSmsNumber);
                if (string.IsNullOrEmpty(activity.ChannelId))
                {
                    _logger.Log(LogLevel.Error, $"{response.Channel} is not supported channel");
                }
                HandleCallbackData(response, activity);

                return(activity);
            }

            if (response.IsSmsMessage())
            {
                _logger.Log(LogLevel.Debug, $"MO message received: MessageId={response.MessageId}, " +
                            $"IntegrationType=SMS, " +
                            $"receivedAt={response.ReceivedAt}");

                var activity = InfobipSmsToActivity.Convert(response);
                HandleCallbackData(response, activity);

                return(activity);
            }

            throw new Exception("Unsupported message received - not DLR, SEEN or MO message: \n" +
                                JsonConvert.SerializeObject(response, Formatting.Indented));
        }