{"id":15524373,"url":"https://github.com/codeforequity-at/botbuilder-storage-rethinkdb","last_synced_at":"2025-03-28T20:48:20.188Z","repository":{"id":91176245,"uuid":"125217178","full_name":"codeforequity-at/botbuilder-storage-rethinkdb","owner":"codeforequity-at","description":"Bot Builder RethinkDB Storage","archived":false,"fork":false,"pushed_at":"2018-03-15T12:02:20.000Z","size":51,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-03T20:02:45.382Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeforequity-at.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-14T13:31:53.000Z","updated_at":"2020-09-01T09:32:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"cde89c04-63d9-4bbc-aa05-ae12e370ab55","html_url":"https://github.com/codeforequity-at/botbuilder-storage-rethinkdb","commit_stats":{"total_commits":8,"total_committers":3,"mean_commits":"2.6666666666666665","dds":0.5,"last_synced_commit":"14870151513a9fd4b190c3c8b1855d4658caf4d6"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforequity-at%2Fbotbuilder-storage-rethinkdb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforequity-at%2Fbotbuilder-storage-rethinkdb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforequity-at%2Fbotbuilder-storage-rethinkdb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeforequity-at%2Fbotbuilder-storage-rethinkdb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeforequity-at","download_url":"https://codeload.github.com/codeforequity-at/botbuilder-storage-rethinkdb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246100489,"owners_count":20723469,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T10:51:06.380Z","updated_at":"2025-03-28T20:48:20.165Z","avatar_url":"https://github.com/codeforequity-at.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bot Builder RethinkDB Storage\n\n**Attention: [Bot Framework State Service will cease operating on March 31st 2018](https://blog.botframework.com/2017/12/19/bot-state-service-will-soon-retired-march-31st-2018/), so you should switch your bot to another storage adapter - like this one - soon!**\n\n[![NPM](https://nodei.co/npm/botbuilder-storage-rethinkdb.png)](https://nodei.co/npm/botbuilder-storage-rethinkdb/)\n\n[ ![Codeship Status for codeforequity-at/botbuilder-storage-rethinkdb](https://app.codeship.com/projects/906d2fd0-0a04-0136-0e62-26e427967e2e/status?branch=master)](https://app.codeship.com/projects/281600)\n[![npm version](https://badge.fury.io/js/botbuilder-storage-rethinkdb.svg)](https://badge.fury.io/js/botbuilder-storage-rethinkdb) \n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)]()\n\nA module to use [RethinkDB](https://www.rethinkdb.com/) as storage adapter for [Microsoft Bot Builder SDK for Node.js](https://github.com/Microsoft/BotBuilder). Configure your bot to automatically save conversation state data in Rethinkdb.\n\n## Installation\n\n```\nnpm install --save botbuilder-storage-rethinkdb\n```\n\n## Usage\n\nInstantiate a new storage, configure connection details to your RethinkDB and plug it into Bot Builder.\n\n```\nconst RethinkDbStorage = require('botbuilder-storage-rethinkdb').RethinkDbStorage;\n\n// BotBuilder setup code\nconst connector = new builder.ChatConnector({\n   ...\n});\nconst bot = new builder.UniversalBot(connector, {\n   ...\n});\n\nconst storage = new RethinkDbStorage({\n  // add your settings here\n  host: '127.0.0.1',\n  tablePrefix: 'botstorage_' + process.env.NODE_ENV\n});\nbot.set('storage', storage);\n\n```\n\n## Configuration\n\nThe constructor take an \"options\" argument. All options for [connecting to RethinkDb](https://rethinkdb.com/api/javascript/connect/) are supported, and some additional ones.\n\n### host\n_Default: 'localhost'_\nWell, the hostname of your RethinkDB instance ...\n\n### port\n_Default: 28015_\nThe port your RethinkDB instance is listening.\n\n### db\n_Default: 'botstorage'_\nThe name of the database to store the conversation state data. If this database doesn't exist, it will be created.\n\n### tablePrefix\n_Default: 'botstorage__'_\nThe table prefix for the conversation state tables, which are created automatically. In case you are sharing one RethinkDB instance among several environments or bots, you should change this table prefix.\n\nThere are 3 tables created automatically, one for each [storage container](https://docs.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-state):\n* botstorage_userData\n* botstorage_conversationData\n* botstorage_privateConversationData\n(botstorage_ is the table prefix)\n\nAll 3 of these tables include:\n* a secondary index for fast lookup\n* a \"created_at\" column\n* a \"updated_at\" column\n\n## Data Migration\n\nHere are some hints how I migrated existing conversation state data from the Bot Framework State Service to my local RethinkDB.\n\nFirst, I enabled a special \"migration\" mode by setting an environment variable. In migration mode, the old storage adapter is used, but the RethinkDB storage adapter is initialized and connected:\n\n```\nconst storage = new RethinkDbStorage({\n  ...\n});\n\nif (process.env.MIGRATE_STORAGE) {\n  require('./migrate')(bot, storage);\n} else {\n  bot.set('storage', storage);\n}\n...\n```\n\nThe migrate.js file loads all existing user addresses from my Redis session store, starts an empty dialog of each of them, making the conversation state data available in the session, and finally stores the conversation state data in RethinkDB.\n\n```\nconst async = require('async');\nconst Redis = require('ioredis');\n\nmodule.exports = (bot, storage) =\u003e {\n\n  var migratedCount = 0;\n  var errorCount = 0;\n\n  const redis = new Redis({\n    host: ...,\n    port: ...,\n    showFriendlyErrorStack: true\n  });\n\n  bot.dialog('/migrate', (session) =\u003e {\n    console.log('MIGRATING USER ' + session.message.address.user.name);\n  \n    const context = {\n      persistUserData: true,\n      userId: session.message.address.user.id,\n      persistConversationData: true,\n      conversationId: session.message.address.conversation.id\n    };\n    const data = {\n      userData: session.userData,\n      conversationData: session.conversationData,\n      privateConversationData: session.privateConversationData\n    }\n    \n    storage.saveData(context, data, (err) =\u003e {\n      if (err) {\n        console.log('SAVEDATA FAILED: ' + err)\n        errorCount++;\n      } else {\n        migratedCount++;\n      }\n      console.log('CURRENTLY MIGRATED: ' + migratedCount + ', ERRORS: ' + errorCount);\n    })\n  })\n\n  async.waterfall([\n\n    (getKeysDone) =\u003e {\n      redis.keys('bot:user:*', getKeysDone);\n    },\n    \n    (keys, getValuesDone) =\u003e {\n      redis.mget(keys, getValuesDone);\n    },\n\n    (values, done) =\u003e {\n      console.log('MIGRATING ' + values.length + ' bot users');\n      \n      values.forEach((address) =\u003e {\n        bot.beginDialog(JSON.parse(address), '/migrate');\n      })\n      done()\n    }\n  ], (err) =\u003e {\n    if (err) {\n      console.log('MIGRATE FAILED: ' + err);\n    }\n  });\n};\n\n```\n\n## License\nMIT\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeforequity-at%2Fbotbuilder-storage-rethinkdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeforequity-at%2Fbotbuilder-storage-rethinkdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeforequity-at%2Fbotbuilder-storage-rethinkdb/lists"}