/// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                //Set the Locale for Bot
                activity.Locale = TemplateUtility.GetLocale(activity);

                var messageActivity = StripBotAtMentions.StripAtMentionText(activity);
                try
                {
                    await Conversation.SendAsync(messageActivity, () => new Dialogs.RootDialog());
                }
                catch (Exception ex)
                {
                }
            }
            else if (activity.Type == ActivityTypes.Invoke) // Received an invoke
            {
                // Handle ComposeExtension query
                if (activity.IsComposeExtensionQuery())
                {
                    var invokeResponse = this.GetComposeExtensionResponse(activity);
                    return(Request.CreateResponse <ComposeExtensionResponse>(HttpStatusCode.OK, invokeResponse));
                }
                else if (activity.IsO365ConnectorCardActionQuery())
                {
                    return(await HandleO365ConnectorCardActionQuery(activity));
                }
                else
                {
                    var messageActivity = (IMessageActivity)null;

                    if (activity.Name == "actionableMessage/executeAction")
                    {
                        messageActivity = ParseInvokeActivityRequest.ParseO365ConnectorCardInvokeRequest(activity);
                    }
                    else
                    {
                        messageActivity = ParseInvokeActivityRequest.ParseInvokeRequest(activity);
                    }

                    await Conversation.SendAsync(messageActivity, () => new Dialogs.RootDialog());

                    // Handle other types of invoke
                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }

            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
        private async Task HandleTextMessageAsync(ConnectorClient client, Activity activity)
        {
            // This is used for removing the '@botName' from the incoming message so it
            // can be parsed correctly
            var messageActivity = activity.Conversation.ConversationType == "personal" ? activity :
                                  StripBotAtMentions.StripAtMentionText(activity);

            try
            {
                // This sends all messages to the RootDialog for processing.
                await Conversation.SendAsync(messageActivity, () => new RootDialog());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
        }
예제 #3
0
        /// <summary>
        /// Processes an <see cref="Activity"/> of <see cref="ActivityTypes.Message"/> type.
        /// </summary>
        /// <param name="activity">The incoming activity from Bot Framework.</param>
        /// <returns>A <see cref="Task"/> that resolves to a <see cref="IHttpActionResult"/> with the response from the API.</returns>
        private async Task <IHttpActionResult> HandleTextMessageAsync(Activity activity)
        {
            // This is used for removing the '@botName' from the incoming message so it can
            // be parsed correctly
            var messageActivity = StripBotAtMentions.StripAtMentionText(activity);

            try
            {
                // This sends all messages to the RootDialog for processing.
                await Conversation.SendAsync(messageActivity, () => new RootDialog());
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return(Ok());
        }