This middleware plugin for Botkit allows developers to easily integrate Gamalon's classification service.
- Run
npm install. - Get your
CLIENT_ID,CLIENT_SECRETandTREE_IDfrom Gamalon. - Create a
.envfile that should look as follows:
CLIENT_ID=<your Gamalon client id>
CLIENT_SECRET=<your Gamalon client secret>
TREE_ID=<your Gamalon tree id>
- Run
node . - Navigate to
localhost:3000to see the chatbot. It will spit out the classification results of any message you type.
skills/gamalon.js contains an example of how you might use the middleware.
- First you'll want to instantiate the middleware, passing in the client id, client secret, and tree id. This will tell the middleware which tree should be used for classification.
const gamalonMiddleware = require('../gamalonMiddleware')({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
treeId: process.env.TREE_ID,
});- Once you've created the middleware, you can to use it. Gamalon's middleware can be used at any step of the incoming messages pipeline:
ingest,normalize,categorize,receive. Below is an example of adding it to thereceivestep.
controller.middleware.receive.use(gamalonMiddleware);- The middleware classifies the text from the
messageand adds the results tomessage.gamalon. It has the following fields:error- A string that describes the error. If it is truthy, then an error has occurred and you should have your bot respond appropriately. Otherwise the classification results can be used.intent- The name of the intent with the highest probability.confidence- The confidence of the classification.path- The path is the tree that leads to the intent.
controller.on('message_received', function(bot, message) {
const { error, intent, confidence, path } = message.gamalon;
//...
});To run test use npm test. You must have your client id, client secret, and tree id in the
.env file.
- Copy the
gamalonMiddlewaredirectory into your project. - Run
npm install --save request