-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add local Botkit CMS plugin to load a local scripts file #1851
Add local Botkit CMS plugin to load a local scripts file #1851
Conversation
I will review ASAP. |
@benbrown Great! I fiddled a bit with the naming and refactored to make some parts reusable, so if you have any preference to keep things more consistent just let me know. |
@etiennellipse , is it supposed to be backward compatible or is it changing the behavior of the previous uselocalstudio features ? |
@InnoraG It's actually much better ;-) For me, useLocalStudio did not work at all using Botkit 4.6 and the latest Botkit CMS. I was getting the errors described in howdyai/botkit-cms#24 (and then some more). The old API exposed by useLocalStudio is: https://github.com/howdyai/botkit-cms/blob/master/src/botkit_mutagen.js The one exposed by my PR combines the methods exposed by https://github.com/howdyai/botkit/pull/1851/files#diff-e54cf01839fc7d00bea99a8fc031c461 and the So no, it is not the exact same; you can see that the My focus was actually to make it work exactly like the API of the "regular" Botkit CMS plugin. This makes switching from one deployment model to the other seamless. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
It's not stale. I'll fix the conflicts. @benbrown Did you have any time to look at it? Any comments? |
Team, this was my native working solution fixing howdyai/botkit-cms#24 without any change in lib, works in latest version 4.6+ Tricks is to deactivate botkit-plugin-cms one time initial fetching since scripts file is local : const { BotkitCMSHelper } = require(`botkit-plugin-cms`);
const scripts = require(`./cms-scripts/scripts.json`);
// Mutation of apiRequest for local script usage
BotkitCMSHelper.prototype.apiRequest = function apiRequest() {
return new Promise(resolve => {
resolve(scripts);
});
};
controller.usePlugin(
new BotkitCMSHelper({
uri: process.env.cms_uri, // "http://localhost:3000/"
token: process.env.cms_token, // "dontguessit"
})
); Then load into DialogSet using native botkit-cms loadScriptsFromFile, same process/function is used by botkit-cms to render scripts file on its GUI : const localcms = require(`botkit-cms`)();
localcms.useLocalStudio = function useLocalStudio(botkit) {
const mutagen = require(`./own_botkit_mutagen.js`); // .studio. replaced with .plugins.cms.
return mutagen(localcms, botkit);
};
localcms.useLocalStudio(controller);
localcms.loadScriptsFromFile(`./cms-scripts/scripts.json`); Usage is same : controller.ready(() => {
// Same handler as for the existing CMS plugin which start dialog when a trigger is hit
controller.on("message", async (bot, message) => {
const results = await controller.plugins.cms.testTrigger(bot, message);
return results === false;
});
}); It appears keeping handling of local scripts to botkit-cms itself instead of botkit-plugin-cms is future proof since will natively sync and evolve with the cms... |
@InnoraG It's a great workaround, and I thank you for it. I started with your solution; in fact I wanted to apply it so that everybody could use it easily. I tried to modify the CMS to have something that works natively with Botkit 4.5+. While doing so, I discovered that the botkit-cms-plugin does some magic of its own, like binding events and such, which would have been lost. Also, modifying the CMS itself would impact backward-compatibility, so it would have needed to be mitigated somehow; either by having the major version bumped, or by creating 2 "mutagen" implementations that support different botkit versions... What I am offering here is a working plugin that anybody can integrate within their code in 12 lines, almost the same way they would integrate with the Botkit CMS API, and that makes sure both implementations are aligned. Also, by bringing the code in the botkit repository, we make sure it stays aligned with botkit itself. It's easy to use, the API is consistent and it does not impact the CMS itself. If the CMS format or API changes, the existing plugin (the one calling the web API) will need to change, so will this one. This way, they are bundled together, which makes a lot of sense. |
…re/add-local-cms-plugin
Thank you for your continued efforts on this @etiennellipse. I am going to try to get this validated and merged into the next release, and if not, a quick follow up release. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale! Still waiting for review tho ;-) |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@benbrown, have you had a chance to review this one? Our team is evaluating usage of botkit but I don't see how can we use it if we can't load cms content in production from files. Search for loading local files eventually leads to this thread. Maybe I'm missing something. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Not stale! @benbrown, any comments? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
:-( |
Bring back this go ! |
@InnoraG, Can you elaborate more on your solution? I tried to follow what you have mentioned. did not worked for me. I want to run botkit using json file without having bot-cms running. based on what I have understood. by mutating apiRequest function it will solve the getScripts()'s problem. But what about evaluateTrigger()? It is being called when following from bot.js is being executed controller.on('message,direct_message', async (bot, message) => {
let results = false;
results = await controller.plugins.cms.testTrigger(bot, message); // <-- this line calls evaluateTrigger()
console.log(results)
return results === false
}); Thanks in advance. |
Hi @vasani-arpit & team Sorry for bit delay -extract in root folder of a working bot Below is startup flow showing botkit:cms Dialogs loaded from Botkit CMS plus emulator first conversationUpdate activity : Please test and feedback |
Hi @InnoraG Thanks for the reply. I tried your solution ran into error in |
Any update to this issue on v4.15? I still trying to use local scripts.json on botkit |
This adds a version of the Botkit CMS plugin that works by loading a local scripts file, without the need to run a Botkit CMS web app. It fixes howdyai/botkit-cms#24, providing a replacement for this with Botkit 4.5+.
I decided to put this in the
botkit-plugin-cms
package, this way both plugins expose the exact same API and share the same logic when relevant.To use this in your bot, just:
npm install botkit-cms --save
The existing hooks all works with this too; before, after and onChange, the exact same way documented here.
I also brought back some the methods exposed by the existing system: getScripts, getScript and getScriptById.
I would like some feedback on it. If it seems acceptable, I will: