Initialise and wrap result processor logic and provide error handling in ChatShipper channel
npm install @web1on1/initresultprocessorUse this package as a wrapper around result processor logic of ChatShipper. It takes care of:
* Accepting the result from an assignment through the result routing.
* Wraps the business logic inside a neat function. The developer only needs to think about the business logic.
When something goes wrong it:
1. Catches the error
2. Report this in the back channel
3. Offer a retry
4. Notify an error channel (if configured)
``bash`
npm install @web1on1/initresultprocessor
`js
const ChipChat = require('chipchat');
const cs = new ChipChat({ token: process.env.CS2_API_TOKEN });
const { initResultProcessor, ProcessingError } = require('@web1on1/initresultprocessor');
initResultProcessor(cs, 'MYRESULTPROCESSOR', async (message, conversation) => {
const results = get(message, 'results', []);
const result = results.find(r => r.type === 'topic');
const contactId = get(message, 'contact');
if (!contactId) return false;
const contact = await cs.contacts.get(contactId);
conversation.say('I will take care of this result!');
});
exports.cloudfunction = pubsub(async event => cs.ingest(event));
`
is set to no (not yes/true/1) the result will be ignored.Error channel in CS
The Error Channel in CS can be defined by setting the bot instance meta ERROR_CHANNEL to the channel ID.Also in can be achieved by setting the following env variable:
`bash
CS2_ERROR_CHANNEL=5e84a8a34d84280011861970
``* _message.create.contact.command_, for subscription on the _assign_ that comes from the result routing
* _message.create.contact.postback_, for the retry mechanism