typeof_bamberg
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Chat Service

Usage

A callback for an incoming message on a channel can be defined using the registerCallback function, which takes a channel id and a callback function as parameters.

reactToMessage provides the functionality to send a message to a given channel. With MSTeams, this is possible only in the course of a callback function registered with registerCallback. reactToMessage takes one parameter of the type GenericContext, this is an object with the attributes text and channel or teamsContext in the case of a MSTeamsService.

Following, a short example on how to use the services:

import { ChatService } from './ChatService';
import { RocketChatService } from './RocketChatService';

const chatService: ChatService = new RocketChatService();

function bot(message: string): void {
    switch (message.toLowerCase()) {
        case 'hello':
            chatService.reactToMessage({
                text: 'Hi!',
                channel: 'GENERAL',
            });
            chatService.reactToMessage({
                text: 'Are you fine?',
                channel: 'GENERAL',
            });
            break;
        case 'yes':
            chatService.reactToMessage({
                text: "That's great!",
                channel: 'GENERAL',
            });
            break;
        case 'no':
            chatService.reactToMessage({
                text: 'Oh no!',
                channel: 'GENERAL',
            });
            break;
        default:
            break;
    }
}

chatService.registerCallback('GENERAL', bot);

For differences between MSTeams, Slack and RocketChat, see their respecting docs:

Readme

Keywords

none

Package Sidebar

Install

npm i typeof_bamberg

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

641 kB

Total Files

44

Last publish

Collaborators

  • sebastian_m