private async Task <IActivity> ConvertMessageToMessageActivity(InfobipIncomingResult response)
        {
            var activity = Activity.CreateMessageActivity();

            activity.Id          = response.MessageId;
            activity.ChannelId   = InfobipConstants.ChannelName;
            activity.ChannelData = response;
            activity.Recipient   = new ChannelAccount {
                Id = response.To
            };
            activity.From = new ChannelAccount {
                Id = response.From
            };
            activity.Conversation = new ConversationAccount {
                IsGroup = false, Id = response.From
            };
            activity.Timestamp = response.ReceivedAt;

            if (response.Message.Type == InfobipIncomingMessageTypes.Text)
            {
                activity.Text       = response.Message.Text;
                activity.TextFormat = TextFormatTypes.Plain;
            }
            else if (response.Message.Type == InfobipIncomingMessageTypes.Location)
            {
                activity.Entities.Add(new GeoCoordinates
                {
                    Latitude  = response.Message.Latitude,
                    Longitude = response.Message.Longitude
                });
            }
            else if (response.Message.IsMedia())
            {
                var contentType = await _infobipClient.GetContentTypeAsync(response.Message.Url.AbsoluteUri).ConfigureAwait(false);

                activity.Attachments = new List <Attachment>
                {
                    new Attachment
                    {
                        ContentType = contentType,
                        ContentUrl  = response.Message.Url.AbsoluteUri,
                        Name        = response.Message.Caption
                    }
                };
            }
            else
            {
                _logger.Log(LogLevel.Information, $"Received MO message: {response.MessageId} has unsupported message type");
                return(null);
            }

            return(activity);
        }
Ejemplo n.º 2
0
        public static async Task <Activity> Convert(InfobipIncomingResult result, IInfobipClient infobipClient)
        {
            var activity = ConvertToMessage(result);

            activity.ChannelId = InfobipChannel.WhatsApp;

            if (result.Message.Type == InfobipIncomingMessageTypes.Text)
            {
                activity.Text       = result.Message.Text;
                activity.TextFormat = TextFormatTypes.Plain;
            }
            else if (result.Message.Type == InfobipIncomingMessageTypes.Location)
            {
                activity.Entities.Add(new GeoCoordinates
                {
                    Latitude  = result.Message.Latitude,
                    Longitude = result.Message.Longitude
                });
            }
            else if (result.Message.IsMedia())
            {
                var contentType = await infobipClient.GetContentTypeAsync(result.Message.Url.AbsoluteUri).ConfigureAwait(false);

                activity.Attachments = new List <Attachment>
                {
                    new Attachment
                    {
                        ContentType = contentType,
                        ContentUrl  = result.Message.Url.AbsoluteUri,
                        Name        = result.Message.Caption
                    }
                };
            }
            else
            {
                return(null);
            }

            return(activity);
        }