/// <summary> /// Send event handler. This method sends the user bug dataset /// to the Watson Web Service. /// </summary> /// <param name="sender">Button</param> /// <param name="e">Null</param> private void Send_Click(object sender, System.EventArgs e) { if (!textChanged) { return; } try { using (WatsonService service = new WatsonService()) { errorInformation.Tables["Watson"].Rows[0]["UserComment"] = this.Information.Text; errorInformation.Tables["Watson"].Rows[0]["UserEmail"] = this.Email.Text; service.Url = GameConfig.WebRoot + "/watson/watson.asmx"; service.Timeout = 20000; service.ReportError(errorInformation); } MessageBox.Show(this, "Thank you! Your bug/suggestion has been sent to the Terrarium development team successfully.", "Bug Sent"); this.Close(); } catch (Exception exception) { // Catch all exceptions because we don't want the user to get into an infinite loop // and if the website is down, we'll just throw away the data ErrorLog.LogHandledException(exception); MessageBox.Show(this, "Sorry! There was a problem sending your bug: " + exception.Message, "Problem sending bug."); } }
/// <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 = null; try { connector = new ConnectorClient(new Uri(activity.ServiceUrl)); // calculate something for us to return var faceTraits = new List <Trait>(); // return our reply to the user if (activity.Attachments.Count == 1) { FaceConnector faceConnector = new FaceConnector(); var faces = await faceConnector.UploadAndDetectFaces(activity); if (faces.Length > 0) { faceTraits = FaceAnalizer.GetTraitsFromFace(faces[0]); } else { await connector.Conversations.ReplyToActivityAsync(activity.CreateReply("You're so dumb, you can't even take a selfie")); return(Request.CreateResponse(HttpStatusCode.OK));; } var jokeService = new JokeService(); var joke = jokeService.GetJoke(faceTraits); Activity reply = activity.CreateReply(joke); await connector.Conversations.ReplyToActivityAsync(reply); } else { JObject r = await WatsonService.TalkToWatson(activity.Text, activity.Conversation.Id); Dictionary <string, double> map = new Dictionary <string, double>(); foreach (JObject entity in r["entities"]) { map[entity["value"].Value <string>()] = entity["confidence"].Value <double>(); } if (map.Keys.Count > 0) { var jokeService = new JokeService(); var joke = jokeService.GetJoke(new List <Trait> { new Trait { Name = map.Keys.First(), Accuracy = 1.0 } }); Activity reply = activity.CreateReply($"{joke}"); await connector.Conversations.ReplyToActivityAsync(reply); } //var entities = ((IEnumerable<object>)r.Result).ToList()[1]; // var replyText = ((Newtonsoft.Json.Linq.JProperty )entities); } // faceConnector.UploadAndDetectFaces(activity.Attachments) } catch (Exception ex) { if (connector != null) { Activity reply = activity.CreateReply(ex.Message); await connector.Conversations.ReplyToActivityAsync(reply); } } } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }