Search code examples
c#botframeworkbotschatbot

How can i store a message from the user in a variable? (Microsoft Bot Framework)


I am working on a feedback feature for my bot based on the MS Bot Framework. Therefore i want to use the Azure Table Storage to store the feedbacks. Everything works execpt of one point:

At the moment, when the user sends the feedback to the bot, the table-insert process starts. But instead of inserting the message from the user, my placeholder called "moin" gets inserted in the table storage.

// Schlüssel für den Table-Zugriff
                string accountKey = "myKey";
                string accountName = "myStorageAccountName";

                // Schlüssel werden hier für den Table-Eintrag zusammengepackt
                TableQueries tableQueries = new TableQueries
                {
                    accountKey = accountKey,
                    accountName = accountName
                };

                // Werte für den Table-Eintrag
                string rowKey = "1";
                string partitionKey = rowKey;
                string userStatement = "moin";

                // Methode für den Table-Eintrag wird hier ausgeführt
                Task<Boolean> bLinkCreated = tableQueries.InsertURL(partitionKey, rowKey, userStatement);
                bLinkCreated.Wait();

                // Wird ausgeführt, wenn keine KnowledgeBase gefunden wird
                System.Diagnostics.Debug.WriteLine("sending feedback");
                await turnContext.SendActivityAsync(MessageFactory.Text("Thanks for sending the feedback!"), cancellationToken);
                break;

How can i replace my current placeholder with the message sent by the user? Is there a method/function to extract the user message and then replace it with my userStatement variable?


Solution

  • Assume your turncontext is ITurnContext<IMessageActivity> turnContext. Then you can find the message in turnContext.Activity.Text

    string userStatement = turnContext.Activity.Text;