public async Task <bool> SetUserConfigurationsAsync( string userId, BitBucketConversationVariables bitBucketConversationVariables) { if (GetUserConfigurationsAsync(userId) != null) { await MyStorage.DeleteAsync(new[] { userId }); } IDictionary <string, object> defaultConfig = new Dictionary <string, object>(); defaultConfig.Add(userId, JObject.Parse(JsonConvert.SerializeObject(bitBucketConversationVariables))); await MyStorage.WriteAsync(defaultConfig); return(true); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { try { var messageDeets = new MessageRecord(); messageDeets.MessageTime = turnContext.Activity.Timestamp.ToString(); messageDeets.MesageText = turnContext.Activity.Text; messageDeets.MessageFrom = turnContext.Activity.From.Name; messageDeets.MessageTo = turnContext.Activity.Recipient.Name; var changes = new Dictionary <string, object>(); { changes.Add("MessageRecords", messageDeets); } await MyStorage.WriteAsync(changes, cancellationToken); await turnContext.SendActivityAsync($"Your message was saved"); } catch { await turnContext.SendActivityAsync($"Your message was all f****d up"); } }
// Tutorial integrating QnA to Bot (bir) /* * public QnAMaker EchoBotQnA { get; private set; } * public EchoBot(QnAMakerEndpoint endpoint) * { * // connects to QnA Maker endpoint for each turn * EchoBotQnA = new QnAMaker(endpoint); * } */ protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { var replyText = $"Ich wiederholeV2: {turnContext.Activity.Text}"; //Easter Egg (Robert, bir) if (turnContext.Activity.Text.ToLower().Contains("tür") && turnContext.Activity.Text.ToLower().Contains("öffne")) { string[] keys = { "door" }; IDictionary <string, object> triesDoorColl = doorStorage.ReadAsync(keys, cancellationToken).Result; int triesDoor = (int)triesDoorColl["doorTries"]; // int triesDoor = Convert.ToInt32(triesDoorStr); replyText = $"Du kannst die Tür nicht öffnen! Es wurde schon {triesDoor} mal versucht, die Tür zu öffnen"; triesDoor++; // triesDoorStr = Convert.ToString(triesDoor); triesDoorColl["doorTries"] = triesDoor; await doorStorage.WriteAsync(triesDoorColl, cancellationToken); } if (turnContext.Activity.Text.ToLower().Contains("hintertür") && turnContext.Activity.Text.ToLower().Contains("öffne")) { string[] keys = { "backdoorTries" }; IDictionary <string, object> triesDoorColl = doorStorage.ReadAsync(keys, cancellationToken).Result; string triesDoorStr = (string)triesDoorColl["doorTries"]; int triesBackdoor = Convert.ToInt32(triesDoorStr); replyText = $"Warum hast du nicht früher drangedacht?! Die Hintertür wurde schon {triesBackdoor} mal benutzt"; triesBackdoor++; triesDoorStr = Convert.ToString(triesBackdoor); triesDoorColl["backdoorTries"] = triesDoorStr; await doorStorage.WriteAsync(triesDoorColl, cancellationToken); } await turnContext.SendActivityAsync(MessageFactory.Text(replyText, replyText), cancellationToken); }
private async Task writeDataToDb(FunctionItem[] functionItems) { if (query == null) { Console.WriteLine("NULL"); } var changes = new Dictionary <string, object>(); changes.Add("function_list", functionItems); await query.WriteAsync(changes, cancellationToken); }
// Sends Personal Data to database public static async void WriteToDB(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Send to DB var changes = new Dictionary <string, object>() { { PersonalDetailsDialog.PersonalDetails.UserID, PersonalDetailsDialog.PersonalDetails } }; try { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed CosmosDBQuery.WriteAsync(changes, cancellationToken); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } catch (Exception e) { await stepContext.Context.SendActivityAsync($"Error while connecting to database.\n\n{e}"); } }
// Sends questionnaires to database public static async void SendQuestionnairesToDB(string name, List <QuestionTopFive> questions, WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Send to DB var pair = new KeyValuePair <string, List <QuestionTopFive> >(name, questions); var changes = new Dictionary <string, object>() { { name, pair } }; try { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed CosmosDBQuestionnaireQuery.WriteAsync(changes, cancellationToken); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } catch (Exception e) { await stepContext.Context.SendActivityAsync($"Error while connecting to database.\n\n{e}"); } }
/* Method from Microsoft Bot Framework doccumentation*/ protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { // preserve user input. var utterance = turnContext.Activity.Text; // make empty local logitems list. UtteranceLog logItems = null; // see if there are previous messages saved in storage. string[] utteranceList = { "UtteranceLog" }; logItems = query.ReadAsync <UtteranceLog>(utteranceList).Result?.FirstOrDefault().Value; // If no stored messages were found, create and store a new entry. if (logItems is null) { // add the current utterance to a new object. logItems = new UtteranceLog(); logItems.UtteranceList.Add(utterance); // set initial turn counter to 1. logItems.TurnNumber++; // Create Dictionary object to hold received user messages. var changes = new Dictionary <string, object>(); { changes.Add("UtteranceLog", logItems); } try { // Save the user message to your Storage. await query.WriteAsync(changes, cancellationToken); } catch { } } // Else, our Storage already contained saved user messages, add new one to the list. else { // add new message to list of messages to display. logItems.UtteranceList.Add(utterance); // increment turn counter. logItems.TurnNumber++; // Create Dictionary object to hold new list of messages. var changes = new Dictionary <string, object>(); { changes.Add("UtteranceLog", logItems); }; try { // Save new list to your Storage. await query.WriteAsync(changes, cancellationToken); } catch { // Inform the user an error occured. //await turnContext.SendActivityAsync("Sorry, something went wrong storing your message!"); } } Logger.LogInformation("Running dialog with Message Activity."); // Run the Dialog with the new message Activity. await Dialog.RunAsync(turnContext, ConversationState.CreateProperty <DialogState>("DialogState"), cancellationToken); }