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)
        {
            if (activity.Type == ActivityTypes.Message)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                //var thinking = activity.CreateReply("Just a sec. Thinking...");
                //await connector.Conversations.ReplyToActivityAsync(thinking);

                //var typing = activity.CreateReply();
                //typing.Type = ActivityTypes.Typing;
                //await connector.Conversations.ReplyToActivityAsync(typing);
                //await Task.Delay(1000);

                try
                {
                    var prediction = await _weatherClient.Forecast(activity.Text);
                    var reply = activity.CreateReply($"Here is your forecast for {prediction?[0].City}:  \n {String.Join("  \n", prediction.Select(p => p.ToString()))}");
                    await connector.Conversations.ReplyToActivityAsync(reply);
                }
                catch (Exception)
                {
                    var error = activity.CreateReply($"Cannot find forecast for \"{activity.Text ?? "NULL"}\"");
                    await connector.Conversations.ReplyToActivityAsync(error);
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
Ejemplo n.º 2
0
 public async Task<Activity> HandleChat(ConnectorClient connector, Activity message) {
     Activity replyToConversation;
     replyToConversation = message.CreateReply(await GetReplyFromLuis(message.Text));
     await connector.Conversations.SendToConversationAsync(replyToConversation);
     Activity proCards = AddRoofHeroCards(replyToConversation);
     await connector.Conversations.SendToConversationAsync(proCards);
     return replyToConversation;
 }
        /// <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)
            {
                bool bSetStock = false;
                Luis.StockLUIS stLuis = await Luis.LUISStockClient.ParseUserInput(activity.Text);
                string strRet = string.Empty;
                string strStock = activity.Text;

                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

                // Get the stateClient to get/set Bot Data
                StateClient _stateClient = activity.GetStateClient();
                BotData _botData = _stateClient.BotState.GetUserData(activity.ChannelId, activity.Conversation.Id);

                switch (stLuis.intents[0].intent)
                {
                    case "RepeatLastStock":
                        strStock = _botData.GetProperty<string>("LastStock");

                        if (null == strStock)
                        {
                            strRet = "I don't have a previous stock to look up!";
                        }
                        else
                        {
                            strRet = await YahooStock.Yahoo.GetStock(strStock);
                        }
                        break;
                    case "StockPrice":
                        bSetStock = true;
                        strRet = await YahooStock.Yahoo.GetStock(stLuis.entities[0].entity);
                        break;
                    case "None":
                        strRet = "Sorry, I don't understand, perhaps try something like \"Show me Microsoft stock\"";
                        break;
                    default:
                        break;
                }

                if (bSetStock)
                {
                    _botData.SetProperty<string>("LastStock", stLuis.entities[0].entity);
                    _stateClient.BotState.SetUserData(activity.ChannelId, activity.Conversation.Id, _botData);
                }
                // return our reply to the user
                Activity reply = activity.CreateReply(strRet);
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
Ejemplo n.º 4
0
        /// <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)
                return Request.CreateResponse(HttpStatusCode.OK);
            if (string.IsNullOrWhiteSpace(activity.Text))
                return Request.CreateResponse(HttpStatusCode.OK);

            var connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            var echoMessage = $"You sent \"{activity.Text}\".";
            await Reply(connector, activity, echoMessage);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
        public async Task<HttpResponseMessage> Post([FromBody]Activity message) {
            ChatBot chat = new ChatBot();
            if (message.Type == ActivityTypes.Message) {
                ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));

                Activity replyToConversation = await chat.HandleChat(connector, message);

               // await connector.Conversations.SendToConversationAsync(replyToConversation);
            }
            else {
                HandleSystemMessage(message);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        public async Task<HttpResponseMessage> Post([FromBody]Activity message) {
            if (message.Type == ActivityTypes.Message) {
                ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
                // calculate something for us to return
                int length = (message.Text ?? string.Empty).Length;

                Activity replyToConversation = CreateCard(message);

                await connector.Conversations.SendToConversationAsync(replyToConversation);
            }
            else {
                HandleSystemMessage(message);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
Ejemplo n.º 7
0
        /// <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)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

                QueryInformation queryInfo = GetQueryInformation(activity.Text);

                Activity reply = activity.CreateReply($"You sent {activity.Text}, but we don't know what that means.");

                if (queryInfo.IsHelpQuestion)
                {
                    reply = activity.CreateReply($"I am a bot that helps you find somebody within the company. i.e. 'Who owns OSI?'");
                }
                else if (queryInfo.IsWhoQuestion)
                {
                    try
                    {
                        if (String.IsNullOrEmpty(queryInfo.Entity))
                        {
                            reply = activity.CreateReply($"We don't know about that sentence structure or technology yet.");
                        }
                        else
                        {
                            // reply = activity.CreateReply($"You sent {activity.Text}, and we found role {queryInfo.Role} and entity {queryInfo.Entity}, and IsWhoQuestion is: {queryInfo.IsWhoQuestion}");
                            var upn = await ContactLookup.Lookup(queryInfo.Entity);

                            reply = activity.CreateReply($"I think a good contact might be {upn}.");
                        }
                    }
                    catch (Exception e)
                    {
                        reply = activity.CreateReply($"I crashed! {e.Message}");
                    }
                }

                // return our reply to the user
                //Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
        private void RetrieveWindowsStoreData(LuisMessage message)
        {
            Task.Run(async () =>
            {
                var connector = new ConnectorClient();

                var client = new Sparkiy.WindowsStore.Analytics.Client.AnalyticsClient();
                await client.AuthorizeAsync(Keys.WindowsStoreAnalyticsId, Keys.WindowsStoreAnalyticsKey);

                var appNames = message.Luis.Entities.Where(e => e.Type == "StoreApp");
                foreach (var entity in appNames)
                {
                    // TODO Resolve application id from database
                    string appId = string.Empty;
                    if (entity.Entity == "sparkiy")
                        appId = "9NBLGGH10R5Z";
                    else if (entity.Entity == "quantastic")
                        appId = "9WZDNCRDRKSB";
                    else
                    {
                        connector.Messages.SendMessage(
                            message.CreateReplyMessage($"I don't know an app named {entity.Entity}.", "en"));
                        continue;
                    }

                    var storeResponse = (await client.GetAppAcquisitionsAsync(appId, DateTime.MinValue, DateTime.MaxValue, 1000, 0, true)).ToList();

                    var lastWeekDate = DateTime.Now.ToUniversalTime().Subtract(TimeSpan.FromDays(7)).ToUniversalTime().Date;
                    var totalAcquisitionsCount = storeResponse
                        .Sum(a => a.AcquisitionQuantity)
                        .ToString(CultureInfo.InvariantCulture);
                    var dayAcquisitionsCount = storeResponse
                        .Where(a => a.Date >= lastWeekDate)
                        .Sum(a => a.AcquisitionQuantity)
                        .ToString(CultureInfo.InvariantCulture);

                    connector.Messages.SendMessage(
                        message.CreateReplyMessage(
                            $"{entity.Entity} has total {totalAcquisitionsCount} (+{dayAcquisitionsCount} last 7 days) acquisitions",
                            "en"));
                }
            });
        }
Ejemplo n.º 9
0
        /// <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)
                return Request.CreateResponse(HttpStatusCode.OK);
            if (string.IsNullOrWhiteSpace(activity.Text))
                return Request.CreateResponse(HttpStatusCode.OK);

            var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
            // In Slack, URLs are qualified by '<' and '>'.
            var text = activity.Text.Trim('<', '>');

            var echoMessage = $"You sent this picture.  \n![]({text})";
            await Reply(connector, activity, echoMessage);

            var mainMessage = await GetEmotionsAsync(text);
            await Reply(connector, activity, mainMessage);

            return Request.CreateResponse(HttpStatusCode.OK);
        }
Ejemplo n.º 10
0
        /// <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)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                // Get Stock information, show user.
                string strRet = await YahooStock.Yahoo.GetStock(activity.Text);

                // return our reply to the user
                Activity reply = activity.CreateReply(strRet);

                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
Ejemplo n.º 11
0
        /// <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)
            {
                ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
                // calculate something for us to return
                string queryString = (activity.Text ?? string.Empty);
                string city = string.Empty;
                string replyMsg = string.Empty;


                var lData = await LuisService.ParseUserInput(queryString);

                if (lData != null)
                {
                    if (lData.intents.Count() > 1)
                    {
                        switch (lData.intents[0].intent)
                        {
                            case "GetWeather":
                                {
                                    if (lData.entities.Count() == 0)
                                    {
                                        replyMsg = "do not know where you are looking for?";
                                    }
                                    else if (lData.entities[0].type == "City")
                                    {
                                        city = lData.entities[0].entity;
                                        replyMsg = await GetWeather(city);
                                    }
                                    else
                                        replyMsg = "I do not understand your city...";

                                }
                                break;
                            default:
                                {
                                    replyMsg = "I can only check the weather now...";
                                    break;
                                }

                        }
                    }

                    else
                        replyMsg = "I do not understand your quesiton";
                       


                }
                else
                    replyMsg = "Sorry I do not understand, please speak English";

                // return our reply to the user
               
                Activity reply = activity.CreateReply(replyMsg);
                await connector.Conversations.ReplyToActivityAsync(reply);
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);
            return response;
        }
Ejemplo n.º 12
0
 static async Task Reply(ConnectorClient connector, Activity activity, string message)
 {
     var reply = activity.CreateReply(message);
     await connector.Conversations.ReplyToActivityAsync(reply);
 }
Ejemplo n.º 13
0
 partial void CustomInitialize()
 {
     ConnectorClient.AddUserAgent(this);
 }