UNPKG

zcatalyst-integ-cliq

Version:

Node.js SDK for integrating Zoho Catalyst with Zoho Cliq

54 lines (53 loc) 2.13 kB
import { Handler } from '../../handler.js'; import HandlerResponse from '../response-objects/handler-response.js'; import CONSTANTS from '../../constants.js'; import { sendRequest } from '../../util.js'; import { CatalystError } from '../../error.js'; import VoidResponse from '../response-objects/void-response.js'; import { Message } from '../response-objects/message.js'; const { BOT } = CONSTANTS; const { bot_handler } = CONSTANTS.HANDLERS; export default class BotHandler { constructor() { this.util = { async getAttachedFile(attachments) { const files = await Promise.all(attachments.map((attachment) => { return sendRequest(attachment.url, 'GET'); })).catch((err) => { throw new CatalystError('Error when getting the attached file', 0, err); }); return files.map((file) => file.buffer); } }; } welcomeHandler(handler) { Handler.registerHandler(BOT, bot_handler.WELCOME_HANDLER, handler, Message); } messageHandler(handler) { Handler.registerHandler(BOT, bot_handler.MESSAGE_HANDLER, handler, HandlerResponse); } contextHandler(handler) { Handler.registerHandler(BOT, bot_handler.CONTEXT_HANDLER, handler, HandlerResponse); } mentionHandler(handler) { Handler.registerHandler(BOT, bot_handler.MENTION_HANDLER, handler, HandlerResponse); } menuActionHandler(handler) { Handler.registerHandler(BOT, bot_handler.ACTION_HANDLER, handler, HandlerResponse); } webHookHandler(handler) { Handler.registerHandler(BOT, bot_handler.INCOMING_WEBHOOK_HANDLER, handler, HandlerResponse); } participationHandler(handler) { Handler.registerHandler(BOT, bot_handler.PARTICIPATION_HANDLER, handler, HandlerResponse); } callHandler(handler) { Handler.registerHandler(BOT, bot_handler.ALERT_HANDLER, handler, VoidResponse); } newHandlerResponse() { return new HandlerResponse(); } newVoidResponse() { return new VoidResponse(); } }