beginAgain
beginAgain

Reputation: 211

Node.js - Pass Session Variables to a SQL Server function call

In a MS Teams BOT I have working dialog code to ask a series of questions and return the formatted response back to the user in a session like so:

session.send(`Details: <br/>Question1: ${session.dialogData.Question1}   <br/>Question2: ${session.dialogData.Question2} <br/>Question3: ${session.dialogData.Question3}`);

So I know the values I need are in the session variables. Now I want to pass the session variables to an SQL insert function (executeStatement):

    var session_username = session.dialogData.username
    var session_yesterday = session.dialogData.yesterday
    var session_today = session.dialogData.today
    var session_obstacles = session.dialogData.obstacles

    executeStatement(session_username, session_yesterday, session_today, session_obstacles)

I can pass strings and the function works fine. But when I try to pass the session variables like above or just passing session.dialogData.yesterday for instance, straight into the function all of the code runs fine - no errors are thrown - but the session variables are not inserted and 0 rows are returned.

What is the proper way to pass a session variable? Google has not been kind in this regard. :)

Thank you in advance...

Edit:

So I couldn't sleep and had a (weird) idea. Use the session.send when assigning the values to the variable like so:

session_username = session.send(`${session.dialogData.username}`)

or

session_username = session.send(session.dialogData.username)

It writes to the database but it is an [object Object] value. So how do I get to the actual value? Hmmm...Still looking

Edit 2:

To get at the object value I tried:

session_yesterday = session.dialogData.yesterday.text()

and

session_yesterday = session.dialogData.yesterday.value()

For the 1st attempt, .text() I received the following error:

TypeError: Cannot read property 'text' of undefined
at Array.<anonymous> (C:\Developer\dailyStatus\index.js:96:56)
at C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:67:39
at next (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:92:21)
at WaterfallDialog.beforeStep (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:99:9)

at WaterfallDialog.doStep (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:61:14)
at WaterfallDialog.dialogResumed (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\WaterfallDialog.js:46:14)
at Session.endDialogWithResult (C:\Developer\dailyStatus\node_modules\botbuilder\lib\Session.js:358:28)
at PromptText.Prompt.invokeIntent (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\Prompt.js:331:21)
at PromptText.Prompt.replyReceived (C:\Developer\dailyStatus\node_modules\botbuilder\lib\dialogs\Prompt.js:147:18)
at Session.routeToActiveDialog (C:\Developer\dailyStatus\node_modules\botbuilder\lib\Session.js:525:24)
/ - ERROR: Cannot read property 'text' of undefined
/ - Session.endConversation()

Upvotes: 0

Views: 192

Answers (1)

beginAgain
beginAgain

Reputation: 211

I was stubbornly trying to access the variables because I KNEW that the information was there.

I tested going back up into the dialog results.response like below and it worked:

session.dialogData.yesterday = session_yesterday = results.response;

It honestly is still a little odd to me that I couldn't just access the variable directly but oh well - lesson learned I guess.

Thank you

Upvotes: 1

Related Questions