public void Dispose() { if (client != null) { client.Dispose(); } }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { try { if (activity.Type == ActivityTypes.Message) { StateClient stateClient = activity.GetStateClient(); BotData conversationData = await stateClient.BotState.GetConversationDataAsync(activity.ChannelId, activity.Conversation.Id); ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); if (activity.Attachments != null && activity.Attachments.Count > 0) { conversationData.SetProperty <bool>("spokenAnswer", true); activity.Text = await ReconhecimentoService.ReconhecerFala(activity.Attachments[0].ContentUrl); } else { conversationData.SetProperty <bool>("spokenAnswer", false); } await stateClient.BotState.SetConversationDataAsync(activity.ChannelId, activity.Conversation.Id, conversationData); stateClient.Dispose(); stateClient = null; await Conversation.SendAsync(activity, MakeLuisDialog); } else { HandleSystemMessage(activity); } } catch (Exception ex) { ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); Activity reply = activity.CreateReply(ex.Message); await connector.Conversations.ReplyToActivityAsync(reply); Activity reply2 = activity.CreateReply(ex.StackTrace); await connector.Conversations.ReplyToActivityAsync(reply2); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
public void Dispose() { _sc.Dispose(); }