node-telegram-firestore-message-replier
Node module which allows the bot to reply to a random message in the chat.
You just set the probability between 1 and 100 and then the magic happens.
Install:
npm install node-telegram-firestore-message-replier
Use:
First create your own firestore db instance
node-telegram-firestore-message-replier initially works with node-telegram-bot-api.
const TelegramBot = require('node-telegram-bot-api');
const TelegramFirestoreMessageReplier = require('node-telegram-firestore-message-replier');
const bot = new TelegramBot('BOT_TOKEN');
const replier = new TelegramFirestoreMessageReplier({
bot,
firestore: {
credential: require('./serviceKey.json'),
databaseUrl: 'https://YOUR_FIREBASE_URL.firebaseio.com',
docPath: 'collection/chats'
},
showChanceMessage: 'Current chance is CURRENT_CHANCE%',
setChanceMessage: 'Current chance changed from CURRENT_CHANCE% to NEXT_CHANCE%'
});
bot.onText(/^\/chance($|@)/, msg => {
replier.showChance(msg);
});
bot.onText(/^\/chance(@.* )?(.+)?/, (msg, match) => {
const chanceValue = match[2];
replier.setChance(msg, chanceValue);
});
bot.on('message', msg => {
replier.process(
msg,
repliedMsg => {
bot.sendMessage(repliedMsg.chat.id, repliedMsg);
},
repliedMsg => {
}
);
});
Options:
new TelegramFirestoreMessageReplier({
bot: <your bot instance> // previously created bot via node-telegram-bot-api
firestore: <object> // firestore db instance params
showChanceMessage: <string> // set message for show chance command
setChanceMessage: <string> // set message for change chance command
});