CreateDirectConversationAsync - how to set BotState?
I'm using external service to initiate conversation with user from Bot. In this service I set BotState, but in bot it contains different values.
My code:
`
var connector = new ConnectorClient(new Uri(serviceUrl), new MicrosoftAppCredentials());
var conversationId = await connector.Conversations.CreateDirectConversationAsync(botAccount, userAccount);
Activity message = (Activity)Activity.CreateMessageActivity();
message.From = botAccount;
message.Recipient = userAccount;
message.Conversation = new ConversationAccount(id: conversationId.Id);
message.ChannelId = channelId;
message.Text = text;
message.Locale = "en-Us";
try
{
message.ServiceUrl = serviceUrl;
var stateClient = message.GetStateClient();
var botData = new BotData(eTag: "*");
botData.SetProperty(stateKey, stateValue);
await stateClient.BotState.SetUserDataAsync(message.ChannelId, message.From.Id, botData);
}
catch (Exception ex)
{
System.Diagnostics.Trace.TraceError(ex.ToString());
}
await connector.Conversations.SendToConversationAsync(message);`
Where stateValue - custom class with simple properties (one enum(translates to int), one bool, one string values).
In Emulator I see that state was set correctly, but when I receiveing this state in bot - it contains different data.
Please advise, what am I doing wrong?
Anyone?
You set message.From = botAccount but then you use message.From.Id when calling SetUserDataAsync - shouldn't it be the user ID?
hm... I think it should work, will check it later! Thank you!
Can't check because of this error: https://github.com/Microsoft/BotBuilder/issues/2294
I'm going to close this issue for now (as it looks like the other issue has been solved), but feel free to open a new issue for further discussion.