Just a Telegram workshop that I have created for Sunway Tech Club. ✨

Slides are not completed to extent of my original intention, which is to make it a standalone tutorial that explains itself. I’ll probably get around to it when I have free time. But for now, this will have to do.

Also, the GitHub repository consists of the completed bots that I intended to teach for the workshop, but ended up only teaching 3 out of the 7 bots due to time constraints and unforseen circumstances. You can find the full code below

Slides here

GitHub repository here

Example bot that uses custom keyboard to roll dice:

const tokenerer = require('../../token');
const token = tokenerer.tokener();

const TelegramBot = require('node-telegram-bot-api');
const bot = new TelegramBot(token, { polling: true });

bot.onText(/\/roll/g, (msg, match) => {
  var chatId = msg.chat.id;

  const customKeyboard = {
    reply_markup: {
      keyboard: [['d6', '2d6'], ['d20', '2d20']],
      resize_keyboard: true
    }
  };

  bot.sendMessage(chatId, 'Choose your weapon!', customKeyboard);
});

bot.onText(/^d6/g, (msg, match) => {
  var chatId = msg.chat.id;
  var roll = dice(6);
  bot.sendMessage(chatId, roll);
});

bot.onText(/^2d6/g, (msg, match) => {
  var chatId = msg.chat.id;
  var roll1 = dice(6);
  var roll2 = dice(6);
  var total = roll1 + roll2;
  bot.sendMessage(chatId, roll1 + ' + ' + roll2 + ' = ' + total);
});

bot.onText(/^d20/g, (msg, match) => {
  var chatId = msg.chat.id;
  var roll = dice(20);
  bot.sendMessage(chatId, roll);
});

bot.onText(/^2d20/g, (msg, match) => {
  var chatId = msg.chat.id;
  var roll1 = dice(20);
  var roll2 = dice(20);
  var total = roll1 + roll2;
  bot.sendMessage(chatId, roll1 + ' + ' + roll2 + ' = ' + total);
});

var dice = sides => Math.floor(Math.random() * sides) + 1;