Example #1
0
        /// <summary>
        /// Build Bot Activity type from the inbound MessageBird request payload<see cref="Activity"/>
        /// </summary>
        /// <param name = "messagePayload"> Message Bird Activity Payload</param>
        /// <returns>Direct Line Activity</returns>
        public static Activity PayloadToActivity(MessageBirdRequestModel messagePayload)
        {
            if (messagePayload == null)
            {
                throw new ArgumentNullException(nameof(messagePayload));
            }

            if (messagePayload.Message?.Direction == ConversationMessageDirection.Sent ||
                messagePayload.Type == ConversationWebhookMessageType.MessageUpdated)
            {
                return(null);
            }

            var channelData = new ActivityExtension
            {
                ChannelType = ChannelType.MessageBird,

                // Add Conversation Context in below dictionary object. Please refer the document for more information.
                ConversationContext = new Dictionary <string, string>(),

                // Add Customer Context in below dictionary object. Please refer the document for more information.
                CustomerContext = new Dictionary <string, string>()
            };

            var activity = new Activity
            {
                From        = new ChannelAccount(messagePayload.Message?.From, messagePayload.Contact?.DisplayName),
                ChannelId   = Constant.ChannelId,
                ServiceUrl  = Constant.DirectLineBotServiceUrl,
                Text        = messagePayload.Message?.Content?.Text,
                Type        = ActivityTypes.Message,
                Id          = messagePayload.Message?.ChannelId,
                ChannelData = channelData
            };

            return(activity);
        }
Example #2
0
        /// <summary>
        /// Creates Direct Line Bot Activity object from a Bot Framework <see cref="Activity"/>
        /// </summary>
        /// <param name="eventInfo">Line Message Event</param>
        /// <param name="userProfile">User Profile</param>
        /// <returns>Activity</returns>
        public static Activity PayloadToActivity(MessageEvent eventInfo, UserProfile userProfile)
        {
            if (eventInfo == null)
            {
                throw new ArgumentNullException(nameof(eventInfo));
            }

            if (userProfile == null)
            {
                throw new ArgumentNullException(nameof(userProfile));
            }

            var message     = (TextEventMessage)eventInfo.Message;
            var channelData = new ActivityExtension
            {
                ChannelType = ChannelType.Line,

                // Add Conversation Context in below dictionary object. Please refer the design document for more information.
                ConversationContext = new Dictionary <string, string>(),

                // Add Customer Context in below dictionary object. Please refer the design document for more information.
                CustomerContext = new Dictionary <string, string>()
            };

            var activity = new Activity
            {
                From        = new ChannelAccount(userProfile.UserId, userProfile.DisplayName),
                Text        = message.Text,
                Type        = ActivityTypes.Message,
                Id          = message.Id,
                ServiceUrl  = Constant.DirectLineBotServiceUrl,
                ChannelData = channelData
            };

            return(activity);
        }