Skip to content

Telegram Service

rz91stud edited this page Jul 30, 2018 · 5 revisions

The Telegram Service contains the backend for your Telegram Bot. It uses NodeJS and Telegraf (NodeJS Telegram Bot API). When a user types a message to your bot, the Telegram Service will know and decide how to handle the message.

Structure

  • bot.js
  • http_service.js
  • message_service.js

bot.js

The bot.js uses Telegraf to build the Bot and to install event-handling. Every command that is supported and every message that will get an answer can be found there.

bot.command('start', (ctx) => {
    ctx.reply(messages.start_msg);
});

For example this code snippet tells the bot if he gets the command /start how to answer

http_service.js

The http_service.js forms the interface to the NSpM Service. There are functions like

  • post_question()
  • post_query()
  • post_training()

to connect to the NSpM Service via HTTP and get the infos you need to answer to the user.

message_service.js

The message_service is basically an array of strings which contains all phrases the bot know.

Clone this wiki locally