public static async Task <string> GetStock(string strStock) { string strRet = string.Empty; double?dblStock = await Yahoo.GetStockPriceAsync(strStock); if (null == dblStock) // might be a company name rather than a stock ticker name { string strTicker = await GetStockTickerName(strStock); if (string.Empty != strTicker) { dblStock = await Yahoo.GetStockPriceAsync(strTicker); strStock = strTicker; } } // return our reply to the user if (null == dblStock) { strRet = string.Format("Stock {0} doesn't appear to be valid", strStock.ToUpper()); } else { strRet = string.Format("Stock: {0}, Value: {1}", strStock.ToUpper(), dblStock); } return(strRet); }
/// <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 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); }