Botframework V4: Python Cosmos DB config

Viewed 166

I am currently trying to use CosmosDB as state storage but encountering some issues when the bot attempts to save the state in CosmosDB.

Below is the code that I am using CosmosDB as the middleware

LOOP = asyncio.get_event_loop()
APP = Flask(__name__)
APP.config.update(VaultConfig.get_config())
APP.wsgi_app = BotTelemetryMiddleware(APP.wsgi_app)
PORT = APP.config["Settings"]["Port"]
INSTRUMENTATION_KEY = APP.config['Settings']["appinsight_instrumentation_key"]
TELEMETRY_CLIENT = ApplicationInsightsTelemetryClient(INSTRUMENTATION_KEY)
SETTINGS = BotFrameworkAdapterSettings(
    APP.config["Settings"]["AppId"], APP.config["Settings"]["AppPassword"]
)

cosmos_config = APP.config['COSMOS']
# Create CosmosStorage and ConversationState
cosmos = CosmosDbStorage(CosmosDbConfig(endpoint=cosmos_config['endpoint'], masterkey=cosmos_config['masterKey'],
                                         database=cosmos_config['database'], container=cosmos_config['container'], partition_key='/id'))
# Create MemoryStorage, UserState and ConversationState


USER_STATE = UserState(cosmos)
CONVERSATION_STATE = ConversationState(cosmos)
ADAPTER = BotFrameworkAdapter(SETTINGS)
ADAPTER.on_turn_error = on_error

The error that I am receiving:

Traceback (most recent call last):
  File "/bot/venv/lib/python3.7/site-packages/botbuilder/core/bot_adapter.py", line 95, in run_pipeline
    context, callback
  File "/bot/venv/lib/python3.7/site-packages/botbuilder/core/middleware_set.py", line 69, in receive_activity_with_status
    return await self.receive_activity_internal(context, callback)
  File "/bot/venv/lib/python3.7/site-packages/botbuilder/core/middleware_set.py", line 79, in receive_activity_internal
    return await callback(context)
  File "/bot/main.py", line 146, in aux_func
    await BOT.on_turn(turn_context)
  File "/bot/bots/dialog_bot.py", line 46, in on_turn
    await self.conversation_state.save_changes(turn_context, False)
  File "/bot/venv/lib/python3.7/site-packages/botbuilder/core/bot_state.py", line 88, in save_changes
    await self._storage.write(changes)
  File "/bot/venv/lib/python3.7/site-packages/botbuilder/azure/cosmosdb_storage.py", line 196, in write
    raise error
  File "/bot/venv/lib/python3.7/site-packages/botbuilder/azure/cosmosdb_storage.py", line 168, in write
    e_tag = change.e_tag
AttributeError: 'dict' object has no attribute 'e_tag'

Attempting to modify this file /bot/venv/lib/python3.7/site-packages/botbuilder/azure/cosmosdb_storage.py for a temporary patch seems to lead me down a rabbit hole that makes it seems like CosmosDB is not fully implemented/tested to be used yet. Am I doing this right?

There were no current samples to work with.

1 Answers
Related