1
votes

I am trying to better understand how state in botframework works.

By default it is said that the state of a bot is stored at https://state.botframework.com. Therefore I should be able to create a blank bot from a template, run fiddler, and see it making a request to the state web service. I cannot see this happening.

I downloaded the botbuilder extensions (And samples) for Azure from this repo here : https://github.com/Microsoft/BotBuilder-Azure . I used the example app for storing data in table storage and it worked! I could see the requests in Fiddler and in my storage account I could see the state/data being saved.

I commented out the Azure code of their example app and ran it. Again I could not see any calls to state.botframework.com

I registered a test bot, and input these credentials as the appId in my bot, I could then see the bot making calls to webchat.botframework.com, but still no calls to store state.

So my questions are.

  1. Where does a bot store it's state by default.
  2. How can I see where it's being stored, so that when I switch to another storage location (Table storage for example), I can be sure it is no longer talking to the default state storage.
1
Have a read of that, it doesn't say when or how it decides to use which state location. I'm half way through working it out, if the channelid on an activity comes through as emulator it's hardcoded to use an internal inmemory state store not the web service. - MindingData
answer to #2 - this information is not available to bot developers at this time - nilsw

1 Answers

1
votes
  1. Where does a bot store it's state by default.

The IBotState REST interface is implemented by two services. The Bot Framework Connector provides a cloud service that implements this interface and stores data in Azure. This data is encrypted at rest and does not intentionally expire. The Bot Framework Emulator provides an in-memory implementation of this interface for debugging your bot. This data expires when the emulator process exits.

from https://docs.microsoft.com/en-us/bot-framework/troubleshoot-general-problems#state-and-data-storage-a-idstatea

The default StateClient's storage path is here in the .net sdk: https://github.com/Microsoft/BotBuilder/blob/b3fff1246348fe93ab2eb1fe654065ccfd863617/CSharp/Library/Microsoft.Bot.Connector.Shared/StateAPI/StateClient.cs#L268

Edit: code in the sdk that checks if the channel is the emulator: https://github.com/Microsoft/BotBuilder/blob/5367ba54b08670a714ab30035ac4316d07be5dc6/CSharp/Library/Microsoft.Bot.Connector.Shared/ActivityEx.cs#L220

2) How can I see where it's being stored, so that when I switch to another storage location (Table storage for example), I can be sure it is no longer talking to the default state storage.

You can host the webchat control on a page, run the bot locally in Visual Studio and use ngrok to redirect traffic from the Connector Service to your local machine:

ngrok http 3979 -host-header="localhost:3979"

Then change the messaging endpoint in https://dev.botframework.com/bots/settings?id=[YourBotHandle] for the bot so instead of https://[SiteName].azurewebsites.net/api/messages it is https://[ngrokpath]/api/messages There’s a nice description of how to set this up here: https://www.robinosborne.co.uk/2016/09/19/debugging-botframework-locally-using-ngrok/

Using this method, you will see calls to state.botframework.com in fiddler.