Bots accessing CosmosDB cause “PreconditionFailed” errorOne CosmosDB state storage for many bots?CosmosDB - bulkDeleteSproc is giving me timeout errorCannot connect to CosmosDb from Azure Bot using NodeMS Bot saving conversation data to Cosmos DBIs it possible to use a partitioned CosmosDB collection as the BotDataStore using botbuilder-azure extensions?CosmosDB $elemMatch syntax errorAzure CosmosDb Stored Procedure IfMatch PredicateRead cosmosDb documents in nodejs botAuthorization error Skype Bot a day laterAccess CosmosDB from different bots
Standard deduction V. mortgage interest deduction - is it basically only for the rich?
Finding the reason behind the value of the integral.
Knowledge-based authentication using Domain-driven Design in C#
Pact of Blade Warlock with Dancing Blade
Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?
How to remove border from elements in the last row?
Forgetting the musical notes while performing in concert
Why is the sentence "Das ist eine Nase" correct?
Which ISO should I use for the cleanest image?
Notepad++ delete until colon for every line with replace all
Is it possible to create a QR code using text?
Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)
Rotate ASCII Art by 45 Degrees
What is required to make GPS signals available indoors?
Why were 5.25" floppy drives cheaper than 8"?
Avoiding the "not like other girls" trope?
What is the fastest integer factorization to break RSA?
Obtaining database information and values in extended properties
In Bayesian inference, why are some terms dropped from the posterior predictive?
Were days ever written as ordinal numbers when writing day-month-year?
Could neural networks be considered metaheuristics?
How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?
Do creatures with a speed 0ft., fly 30ft. (hover) ever touch the ground?
Are British MPs missing the point, with these 'Indicative Votes'?
Bots accessing CosmosDB cause “PreconditionFailed” error
One CosmosDB state storage for many bots?CosmosDB - bulkDeleteSproc is giving me timeout errorCannot connect to CosmosDb from Azure Bot using NodeMS Bot saving conversation data to Cosmos DBIs it possible to use a partitioned CosmosDB collection as the BotDataStore using botbuilder-azure extensions?CosmosDB $elemMatch syntax errorAzure CosmosDb Stored Procedure IfMatch PredicateRead cosmosDb documents in nodejs botAuthorization error Skype Bot a day laterAccess CosmosDB from different bots
I have several bots accessing a CosmosDB. They get a userId through an URL parameter from the client.
My problem appears when using the same bot in different instances at the same time.
Let's say I start a conversation with the userID "1", enter some data like name, age, gender. In the middle of the conversation, I open up another website with the userID "2". User 2 enters name. User 1 finishes profile creation. User 2 is prompted for age. Suddenly, the userID from User 2 changes to "1" and the profile data is identical to the userdata from user 1.
From time to time, I get the following error:
code: 412,
body: ‘“code”:“PreconditionFailed”,“message”:“Operation cannot be performed because one of the specified precondition is not met., rnRequestStartTime: 2019-03-07T20:57:19.6998897Z, RequestEndTime: 2019-03-07T20:57:19.7098745Z, Number of regions attempted: 1rnResponseTime: 2019-03-07T20:57:19.7098745Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westeurope1-fd21.documents.azure.com:16817/apps/9bc5d0cc-9b7c-4b1d-9be2-0fa2654271c4/services/3507a423-5215-48ca-995a-8763ec527db8/partitions/940cd512-aa34-4c93-9596-743de41037da/replicas/131964420031154286p/, LSN: 172, GlobalCommittedLsn: 171, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 412, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: 172, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Replacern, Microsoft.Azure.Documents.Common/2.2.0.0”’,
activityId: ‘fbdaeedb-a73f-4052-bd55-b1417b10583f’
So, the bot seems to mix up the userIDs in some way.
I save UserState and ConversationState in a local storage, since I don't need them saved in my DB:
// Local browser storage
const memoryStorageLocal = new MemoryStorage();
// ConversationState and UserState
const conversationState = new ConversationState(memoryStorageLocal);
const userState = new UserState(memoryStorageLocal);
I obtain the userID as follows, which equals the URL param
for (var idx in turnContext.activity.membersAdded)
if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id)
console.log("User added");
this.userID = turnContext.activity.membersAdded[idx].id;
I read and write to the DB as follows:
// Read userData object
try
user = await this.memoryStorage.read([this.userID]);
console.log("User Object read from DB: " + util.inspect(user, false, null, true /* enable colors */));
catch(e)
console.log("Reading user data failed");
console.log(e);
// If user is new, create UserData object and save it to DB and read it for further use
if(isEmpty(user))
await step.context.sendActivity("New User Detected");
this.changes[this.userID] = this.userData;
await this.memoryStorage.write(this.changes);
user = await this.memoryStorage.read([this.userID]);
This is the "empty" userData object I save to the DB if the user is new:
this.userData =
name: "",
age: "",
gender: "",
education: "",
major: "",
riskData:
roundCounter: "",
riskAssessmentComplete: "",
riskDescription: "",
repeat: "",
choices: "",
,
investData:
repeat: "",
order: "",
choice: "",
follow: "",
win1: "",
win2: "",
loss1: "",
loss2: "",
,
endRepeat: "",
eTag: '*',
To me it seems like the actual problem is not how I read and write from and to the CosmosDB, but that there aren't different instances of the bot as the user IDs and userdata gets mixed up when using them simultaneously.
How can I make this work? You can find my bot code here:
https://github.com/FRANZKAFKA13/roboadvisoryBot
Thanks in advance for any help!
parallel-processing
add a comment |
I have several bots accessing a CosmosDB. They get a userId through an URL parameter from the client.
My problem appears when using the same bot in different instances at the same time.
Let's say I start a conversation with the userID "1", enter some data like name, age, gender. In the middle of the conversation, I open up another website with the userID "2". User 2 enters name. User 1 finishes profile creation. User 2 is prompted for age. Suddenly, the userID from User 2 changes to "1" and the profile data is identical to the userdata from user 1.
From time to time, I get the following error:
code: 412,
body: ‘“code”:“PreconditionFailed”,“message”:“Operation cannot be performed because one of the specified precondition is not met., rnRequestStartTime: 2019-03-07T20:57:19.6998897Z, RequestEndTime: 2019-03-07T20:57:19.7098745Z, Number of regions attempted: 1rnResponseTime: 2019-03-07T20:57:19.7098745Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westeurope1-fd21.documents.azure.com:16817/apps/9bc5d0cc-9b7c-4b1d-9be2-0fa2654271c4/services/3507a423-5215-48ca-995a-8763ec527db8/partitions/940cd512-aa34-4c93-9596-743de41037da/replicas/131964420031154286p/, LSN: 172, GlobalCommittedLsn: 171, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 412, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: 172, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Replacern, Microsoft.Azure.Documents.Common/2.2.0.0”’,
activityId: ‘fbdaeedb-a73f-4052-bd55-b1417b10583f’
So, the bot seems to mix up the userIDs in some way.
I save UserState and ConversationState in a local storage, since I don't need them saved in my DB:
// Local browser storage
const memoryStorageLocal = new MemoryStorage();
// ConversationState and UserState
const conversationState = new ConversationState(memoryStorageLocal);
const userState = new UserState(memoryStorageLocal);
I obtain the userID as follows, which equals the URL param
for (var idx in turnContext.activity.membersAdded)
if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id)
console.log("User added");
this.userID = turnContext.activity.membersAdded[idx].id;
I read and write to the DB as follows:
// Read userData object
try
user = await this.memoryStorage.read([this.userID]);
console.log("User Object read from DB: " + util.inspect(user, false, null, true /* enable colors */));
catch(e)
console.log("Reading user data failed");
console.log(e);
// If user is new, create UserData object and save it to DB and read it for further use
if(isEmpty(user))
await step.context.sendActivity("New User Detected");
this.changes[this.userID] = this.userData;
await this.memoryStorage.write(this.changes);
user = await this.memoryStorage.read([this.userID]);
This is the "empty" userData object I save to the DB if the user is new:
this.userData =
name: "",
age: "",
gender: "",
education: "",
major: "",
riskData:
roundCounter: "",
riskAssessmentComplete: "",
riskDescription: "",
repeat: "",
choices: "",
,
investData:
repeat: "",
order: "",
choice: "",
follow: "",
win1: "",
win2: "",
loss1: "",
loss2: "",
,
endRepeat: "",
eTag: '*',
To me it seems like the actual problem is not how I read and write from and to the CosmosDB, but that there aren't different instances of the bot as the user IDs and userdata gets mixed up when using them simultaneously.
How can I make this work? You can find my bot code here:
https://github.com/FRANZKAFKA13/roboadvisoryBot
Thanks in advance for any help!
parallel-processing
add a comment |
I have several bots accessing a CosmosDB. They get a userId through an URL parameter from the client.
My problem appears when using the same bot in different instances at the same time.
Let's say I start a conversation with the userID "1", enter some data like name, age, gender. In the middle of the conversation, I open up another website with the userID "2". User 2 enters name. User 1 finishes profile creation. User 2 is prompted for age. Suddenly, the userID from User 2 changes to "1" and the profile data is identical to the userdata from user 1.
From time to time, I get the following error:
code: 412,
body: ‘“code”:“PreconditionFailed”,“message”:“Operation cannot be performed because one of the specified precondition is not met., rnRequestStartTime: 2019-03-07T20:57:19.6998897Z, RequestEndTime: 2019-03-07T20:57:19.7098745Z, Number of regions attempted: 1rnResponseTime: 2019-03-07T20:57:19.7098745Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westeurope1-fd21.documents.azure.com:16817/apps/9bc5d0cc-9b7c-4b1d-9be2-0fa2654271c4/services/3507a423-5215-48ca-995a-8763ec527db8/partitions/940cd512-aa34-4c93-9596-743de41037da/replicas/131964420031154286p/, LSN: 172, GlobalCommittedLsn: 171, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 412, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: 172, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Replacern, Microsoft.Azure.Documents.Common/2.2.0.0”’,
activityId: ‘fbdaeedb-a73f-4052-bd55-b1417b10583f’
So, the bot seems to mix up the userIDs in some way.
I save UserState and ConversationState in a local storage, since I don't need them saved in my DB:
// Local browser storage
const memoryStorageLocal = new MemoryStorage();
// ConversationState and UserState
const conversationState = new ConversationState(memoryStorageLocal);
const userState = new UserState(memoryStorageLocal);
I obtain the userID as follows, which equals the URL param
for (var idx in turnContext.activity.membersAdded)
if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id)
console.log("User added");
this.userID = turnContext.activity.membersAdded[idx].id;
I read and write to the DB as follows:
// Read userData object
try
user = await this.memoryStorage.read([this.userID]);
console.log("User Object read from DB: " + util.inspect(user, false, null, true /* enable colors */));
catch(e)
console.log("Reading user data failed");
console.log(e);
// If user is new, create UserData object and save it to DB and read it for further use
if(isEmpty(user))
await step.context.sendActivity("New User Detected");
this.changes[this.userID] = this.userData;
await this.memoryStorage.write(this.changes);
user = await this.memoryStorage.read([this.userID]);
This is the "empty" userData object I save to the DB if the user is new:
this.userData =
name: "",
age: "",
gender: "",
education: "",
major: "",
riskData:
roundCounter: "",
riskAssessmentComplete: "",
riskDescription: "",
repeat: "",
choices: "",
,
investData:
repeat: "",
order: "",
choice: "",
follow: "",
win1: "",
win2: "",
loss1: "",
loss2: "",
,
endRepeat: "",
eTag: '*',
To me it seems like the actual problem is not how I read and write from and to the CosmosDB, but that there aren't different instances of the bot as the user IDs and userdata gets mixed up when using them simultaneously.
How can I make this work? You can find my bot code here:
https://github.com/FRANZKAFKA13/roboadvisoryBot
Thanks in advance for any help!
parallel-processing
I have several bots accessing a CosmosDB. They get a userId through an URL parameter from the client.
My problem appears when using the same bot in different instances at the same time.
Let's say I start a conversation with the userID "1", enter some data like name, age, gender. In the middle of the conversation, I open up another website with the userID "2". User 2 enters name. User 1 finishes profile creation. User 2 is prompted for age. Suddenly, the userID from User 2 changes to "1" and the profile data is identical to the userdata from user 1.
From time to time, I get the following error:
code: 412,
body: ‘“code”:“PreconditionFailed”,“message”:“Operation cannot be performed because one of the specified precondition is not met., rnRequestStartTime: 2019-03-07T20:57:19.6998897Z, RequestEndTime: 2019-03-07T20:57:19.7098745Z, Number of regions attempted: 1rnResponseTime: 2019-03-07T20:57:19.7098745Z, StoreResult: StorePhysicalAddress: rntbd://cdb-ms-prod-westeurope1-fd21.documents.azure.com:16817/apps/9bc5d0cc-9b7c-4b1d-9be2-0fa2654271c4/services/3507a423-5215-48ca-995a-8763ec527db8/partitions/940cd512-aa34-4c93-9596-743de41037da/replicas/131964420031154286p/, LSN: 172, GlobalCommittedLsn: 171, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 412, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: 172, UsingLocalLSN: False, TransportException: null, ResourceType: Document, OperationType: Replacern, Microsoft.Azure.Documents.Common/2.2.0.0”’,
activityId: ‘fbdaeedb-a73f-4052-bd55-b1417b10583f’
So, the bot seems to mix up the userIDs in some way.
I save UserState and ConversationState in a local storage, since I don't need them saved in my DB:
// Local browser storage
const memoryStorageLocal = new MemoryStorage();
// ConversationState and UserState
const conversationState = new ConversationState(memoryStorageLocal);
const userState = new UserState(memoryStorageLocal);
I obtain the userID as follows, which equals the URL param
for (var idx in turnContext.activity.membersAdded)
if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id)
console.log("User added");
this.userID = turnContext.activity.membersAdded[idx].id;
I read and write to the DB as follows:
// Read userData object
try
user = await this.memoryStorage.read([this.userID]);
console.log("User Object read from DB: " + util.inspect(user, false, null, true /* enable colors */));
catch(e)
console.log("Reading user data failed");
console.log(e);
// If user is new, create UserData object and save it to DB and read it for further use
if(isEmpty(user))
await step.context.sendActivity("New User Detected");
this.changes[this.userID] = this.userData;
await this.memoryStorage.write(this.changes);
user = await this.memoryStorage.read([this.userID]);
This is the "empty" userData object I save to the DB if the user is new:
this.userData =
name: "",
age: "",
gender: "",
education: "",
major: "",
riskData:
roundCounter: "",
riskAssessmentComplete: "",
riskDescription: "",
repeat: "",
choices: "",
,
investData:
repeat: "",
order: "",
choice: "",
follow: "",
win1: "",
win2: "",
loss1: "",
loss2: "",
,
endRepeat: "",
eTag: '*',
To me it seems like the actual problem is not how I read and write from and to the CosmosDB, but that there aren't different instances of the bot as the user IDs and userdata gets mixed up when using them simultaneously.
How can I make this work? You can find my bot code here:
https://github.com/FRANZKAFKA13/roboadvisoryBot
Thanks in advance for any help!
parallel-processing
parallel-processing
asked Mar 7 at 21:02
FRANZKAFKAFRANZKAFKA
3310
3310
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It's because you're storing everything in your constructor, which is only called by the bot once. The same instances of this.changes and this.userId are being used by both users at the same time. When one user changes it, it also changes for the other user. It's basically making them global variables that any user has the ability to change.
Instead, you can pass the variables you need to the dialogs using step.options.
For example,
Calling the dialog:
await dc.beginDialog('welcome', userId)
Using within the dialog:
this.userId = step.options // It may also be step.options.userId, if you pass it in as part of a larger object, like .beginDialog('welcome', userId: '123', userName: 'xyz' )
Note
Regarding the way you originally tried this, by instantiating this.userId in the constructor:
You can actually get away with this in C#, since in the C# SDK, the constructor is called on every message (JS/TS it is only called when the bot is first initiated). This major difference exists between BotFramework's JS and C# SDKs because C# is multi-threaded and JS is single-threaded. By calling the constructor on each message in C#, you can spread the load across threads. This isn't possible in JS/TS.
That being said, I would still avoid this as it's better code practice not to use "global" variables when possible.
It worked, thanks a lot! For other people reading this: you should not use "this" within the dialog, as described in the code sample above, since it will lead to the same result as my first approach. Also, at least in my case, I obtained the userId that was given as an option with "userId = step.options", not "step.options.userId".
– FRANZKAFKA
Mar 8 at 15:23
1
@FRANZKAFKA Thanks for the additional note! I've edited my answer to reflect this. Funny thing is, you can actually dothisyour original way in C# because of the way ASP.NET works. I'll edit that into my answer for others once I have a better understanding of it.
– mdrichardson
Mar 8 at 15:52
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052741%2fbots-accessing-cosmosdb-cause-preconditionfailed-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's because you're storing everything in your constructor, which is only called by the bot once. The same instances of this.changes and this.userId are being used by both users at the same time. When one user changes it, it also changes for the other user. It's basically making them global variables that any user has the ability to change.
Instead, you can pass the variables you need to the dialogs using step.options.
For example,
Calling the dialog:
await dc.beginDialog('welcome', userId)
Using within the dialog:
this.userId = step.options // It may also be step.options.userId, if you pass it in as part of a larger object, like .beginDialog('welcome', userId: '123', userName: 'xyz' )
Note
Regarding the way you originally tried this, by instantiating this.userId in the constructor:
You can actually get away with this in C#, since in the C# SDK, the constructor is called on every message (JS/TS it is only called when the bot is first initiated). This major difference exists between BotFramework's JS and C# SDKs because C# is multi-threaded and JS is single-threaded. By calling the constructor on each message in C#, you can spread the load across threads. This isn't possible in JS/TS.
That being said, I would still avoid this as it's better code practice not to use "global" variables when possible.
It worked, thanks a lot! For other people reading this: you should not use "this" within the dialog, as described in the code sample above, since it will lead to the same result as my first approach. Also, at least in my case, I obtained the userId that was given as an option with "userId = step.options", not "step.options.userId".
– FRANZKAFKA
Mar 8 at 15:23
1
@FRANZKAFKA Thanks for the additional note! I've edited my answer to reflect this. Funny thing is, you can actually dothisyour original way in C# because of the way ASP.NET works. I'll edit that into my answer for others once I have a better understanding of it.
– mdrichardson
Mar 8 at 15:52
add a comment |
It's because you're storing everything in your constructor, which is only called by the bot once. The same instances of this.changes and this.userId are being used by both users at the same time. When one user changes it, it also changes for the other user. It's basically making them global variables that any user has the ability to change.
Instead, you can pass the variables you need to the dialogs using step.options.
For example,
Calling the dialog:
await dc.beginDialog('welcome', userId)
Using within the dialog:
this.userId = step.options // It may also be step.options.userId, if you pass it in as part of a larger object, like .beginDialog('welcome', userId: '123', userName: 'xyz' )
Note
Regarding the way you originally tried this, by instantiating this.userId in the constructor:
You can actually get away with this in C#, since in the C# SDK, the constructor is called on every message (JS/TS it is only called when the bot is first initiated). This major difference exists between BotFramework's JS and C# SDKs because C# is multi-threaded and JS is single-threaded. By calling the constructor on each message in C#, you can spread the load across threads. This isn't possible in JS/TS.
That being said, I would still avoid this as it's better code practice not to use "global" variables when possible.
It worked, thanks a lot! For other people reading this: you should not use "this" within the dialog, as described in the code sample above, since it will lead to the same result as my first approach. Also, at least in my case, I obtained the userId that was given as an option with "userId = step.options", not "step.options.userId".
– FRANZKAFKA
Mar 8 at 15:23
1
@FRANZKAFKA Thanks for the additional note! I've edited my answer to reflect this. Funny thing is, you can actually dothisyour original way in C# because of the way ASP.NET works. I'll edit that into my answer for others once I have a better understanding of it.
– mdrichardson
Mar 8 at 15:52
add a comment |
It's because you're storing everything in your constructor, which is only called by the bot once. The same instances of this.changes and this.userId are being used by both users at the same time. When one user changes it, it also changes for the other user. It's basically making them global variables that any user has the ability to change.
Instead, you can pass the variables you need to the dialogs using step.options.
For example,
Calling the dialog:
await dc.beginDialog('welcome', userId)
Using within the dialog:
this.userId = step.options // It may also be step.options.userId, if you pass it in as part of a larger object, like .beginDialog('welcome', userId: '123', userName: 'xyz' )
Note
Regarding the way you originally tried this, by instantiating this.userId in the constructor:
You can actually get away with this in C#, since in the C# SDK, the constructor is called on every message (JS/TS it is only called when the bot is first initiated). This major difference exists between BotFramework's JS and C# SDKs because C# is multi-threaded and JS is single-threaded. By calling the constructor on each message in C#, you can spread the load across threads. This isn't possible in JS/TS.
That being said, I would still avoid this as it's better code practice not to use "global" variables when possible.
It's because you're storing everything in your constructor, which is only called by the bot once. The same instances of this.changes and this.userId are being used by both users at the same time. When one user changes it, it also changes for the other user. It's basically making them global variables that any user has the ability to change.
Instead, you can pass the variables you need to the dialogs using step.options.
For example,
Calling the dialog:
await dc.beginDialog('welcome', userId)
Using within the dialog:
this.userId = step.options // It may also be step.options.userId, if you pass it in as part of a larger object, like .beginDialog('welcome', userId: '123', userName: 'xyz' )
Note
Regarding the way you originally tried this, by instantiating this.userId in the constructor:
You can actually get away with this in C#, since in the C# SDK, the constructor is called on every message (JS/TS it is only called when the bot is first initiated). This major difference exists between BotFramework's JS and C# SDKs because C# is multi-threaded and JS is single-threaded. By calling the constructor on each message in C#, you can spread the load across threads. This isn't possible in JS/TS.
That being said, I would still avoid this as it's better code practice not to use "global" variables when possible.
edited Mar 8 at 18:36
answered Mar 7 at 23:44
mdrichardsonmdrichardson
1,0661111
1,0661111
It worked, thanks a lot! For other people reading this: you should not use "this" within the dialog, as described in the code sample above, since it will lead to the same result as my first approach. Also, at least in my case, I obtained the userId that was given as an option with "userId = step.options", not "step.options.userId".
– FRANZKAFKA
Mar 8 at 15:23
1
@FRANZKAFKA Thanks for the additional note! I've edited my answer to reflect this. Funny thing is, you can actually dothisyour original way in C# because of the way ASP.NET works. I'll edit that into my answer for others once I have a better understanding of it.
– mdrichardson
Mar 8 at 15:52
add a comment |
It worked, thanks a lot! For other people reading this: you should not use "this" within the dialog, as described in the code sample above, since it will lead to the same result as my first approach. Also, at least in my case, I obtained the userId that was given as an option with "userId = step.options", not "step.options.userId".
– FRANZKAFKA
Mar 8 at 15:23
1
@FRANZKAFKA Thanks for the additional note! I've edited my answer to reflect this. Funny thing is, you can actually dothisyour original way in C# because of the way ASP.NET works. I'll edit that into my answer for others once I have a better understanding of it.
– mdrichardson
Mar 8 at 15:52
It worked, thanks a lot! For other people reading this: you should not use "this" within the dialog, as described in the code sample above, since it will lead to the same result as my first approach. Also, at least in my case, I obtained the userId that was given as an option with "userId = step.options", not "step.options.userId".
– FRANZKAFKA
Mar 8 at 15:23
It worked, thanks a lot! For other people reading this: you should not use "this" within the dialog, as described in the code sample above, since it will lead to the same result as my first approach. Also, at least in my case, I obtained the userId that was given as an option with "userId = step.options", not "step.options.userId".
– FRANZKAFKA
Mar 8 at 15:23
1
1
@FRANZKAFKA Thanks for the additional note! I've edited my answer to reflect this. Funny thing is, you can actually do
this your original way in C# because of the way ASP.NET works. I'll edit that into my answer for others once I have a better understanding of it.– mdrichardson
Mar 8 at 15:52
@FRANZKAFKA Thanks for the additional note! I've edited my answer to reflect this. Funny thing is, you can actually do
this your original way in C# because of the way ASP.NET works. I'll edit that into my answer for others once I have a better understanding of it.– mdrichardson
Mar 8 at 15:52
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052741%2fbots-accessing-cosmosdb-cause-preconditionfailed-error%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown