Ejemplo n.º 1
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            if (activity.Type == ActivityTypes.Message)
            {
                // This is the reply from the original template code, kept here for reference
                // int length = (activity.Text ?? string.Empty).Length;
                // Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
                // await connector.Conversations.ReplyToActivityAsync(reply);

                // Parse the user's meaning via Language Understanding (LUIS) in Cognitive Services
                MakerLUIS mkLuis = await LUISMakerShowClient.ParseUserInput(activity.Text);

                string strRet  = string.Empty;
                string strTech = activity.Text;

                if (mkLuis.intents.Count() > 0)
                {
                    switch (mkLuis.intents[0].intent)
                    {
                    case "LearnTopic":
                        strRet = mkLuis.entities.Count() > 0 ? GetResource(mkLuis.entities[0].entity) : "";
                        break;

                    case "BuyHardware":
                        strRet = mkLuis.entities.Count() > 0 ? GetStore(mkLuis.entities[0].entity) : "";
                        break;

                    case "Greeting":
                        strRet = "Hi! I'm the Maker Show Bot and I'm here to help you become a maker";
                        break;

                    case "Help":
                        strRet = "Simply ask me questions about different technologies you want to learn or buy";
                        break;

                    case "ThankYou":
                        strRet = "No problem, happy to help";
                        break;

                    case "Complain":
                        strRet = "I'm sorry, I'm doing my best. Try again, maybe?";
                        break;

                    default:
                        strRet = "I'm sorry, but I'm not sure what you're asking me";
                        break;
                    }
                }
                else
                {
                    strRet = "I'm sorry but I don't understand what you're asking";
                }

                Activity reply = activity.CreateReply(strRet);

                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }

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

            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            if (activity.Type == ActivityTypes.Message)
            {
                // Parse the user's meaning via Language Understanding (LUIS) in Cognitive Services
                MakerLUIS mkLuis = await LUISMakerShowClient.ParseUserInput(activity.Text);

                string strRet  = string.Empty;
                string strTech = activity.Text;

                if (mkLuis.intents.Count() > 0)
                {
                    switch (mkLuis.intents[0].intent)
                    {
                    case "LearnTopic":
                        strRet = mkLuis.entities.Count() > 0 ? GetResource(mkLuis.entities[0].entity) : "";
                        break;

                    case "BuyHardware":
                        strRet = mkLuis.entities.Count() > 0 ? GetStore(mkLuis.entities[0].entity) : "";
                        break;

                    case "WhoIs":
                        strRet = mkLuis.entities.Count() > 0 ? GetPerson(mkLuis.entities[0].entity) : "";
                        break;

                    case "Greeting":
                        strRet = "Hi! I'm the Maker Show Bot and I'm here to help you become a maker";
                        break;

                    case "Help":
                        strRet = "Simply ask me questions about different technologies you want to learn or buy";
                        break;

                    case "ThankYou":
                        strRet = "No problem, happy to help";
                        break;

                    case "Complain":
                        strRet = "I'm sorry, I'm doing my best. Try again, maybe?";
                        break;

                    case "Compare":
                        // TO DO: Ths is a new intent added during a live talk at VSLive.
                        // I need to come back and provide a proper reply build-out here.
                        if (mkLuis.entities.Count() >= 2)
                        {
                            string board1 = mkLuis.entities[0].entity;
                            string board2 = mkLuis.entities[1].entity;
                            strRet = $"Sorry, I don't really know exactly the differences between {board1} and {board2}";
                        }
                        break;

                    default:
                        strRet = "I'm sorry, but I'm not sure what you're asking me";
                        break;
                    }
                }
                else
                {
                    strRet = "I'm sorry but I don't understand what you're asking";
                }

                Activity reply = activity.CreateReply(strRet);

                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }

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

            return(response);
        }