Search code examples
node.jsbotframeworkmicrosoft-teams

How to Store Conversation reference(dictionary) into Azure DB Storage


Im working on a bot with Bot framework v4 in nodejs. I want my Conversation reference for every user to be stored into an azure db. Conversation reference is in a nested dictionary format. {'convid':{"a":'value","b":"value"}}

I want this dictionary to be stored in Azure DB (Which Db would be suitable?free version?Paid?) so that i could later retrieve this DB and send out a proactive messages to all users whose conv ref is stored.

I just want to know how to store dictionary into any azure DB with node js? and retrieve it later? Any help would be appreciated.


Solution

  • Saving the conversation reference during a (private) conversation can be achieved using the following snippet.

    conversationReference = TurnContext.getConversationReference(context.activity);
    

    You can eventually save this JSON directly to CosmosDB using the Cosmos Javascript SDK.

    const databaseDefinition = { id: "sample database" };
    const collectionDefinition = { id: "sample collection" };
    
    const { database } = await client.databases.create(databaseDefinition);
    const { container } = await database.containers.create(collectionDefinition); 
    
    const { resource } = await container.items.create(conversationReference);