Help bot
In Bots.Business chat we have many generic questions. This bot can answer for thems.
Bot have only one command. This command is Master command - *.

Code description

Bot receive all messages from chat with Master command.
So we do not need any notifications about new chat members and etc:
if(!message){ return }
Do you have big case for command execution? You can use return.
Bot have keywords for searching in user's messages. Bot show answer and url on keywoard in message:
list = [
{ url: "", keywords: [ 'status' ],
answer: 'Seems do you need to know uptime status?' },
{ keywords: [ '/start' ], answer: 'Please do not touch it here' },
{ keywords: [ 'php ', ' php' ], answer: 'PHP? Really? I love BJS only' },
{ keywords: [ 'hi!', 'hello' ], answer: 'Hey!' }
Also admin can write anything and do not need any help. So we have key - answerToAdmin:
let admin_tg_id = 519829299;
{ url: "", keywords: [ 'status' ], answerToAdmin: true }
Sometimes we need exact searhing:
{ url: "", keywords: [ 'help' ], exact:true}
Message can be in aNyCAse. We need it only in lowercase:
let stext = message.toLowerCase();
We use functions in the code. So code more simple:
// search keyword in the message (stext)
function haveAnyKeyword(item){
for(var ind in item.keywords){
// exact searhing
// exact searching
if(stext==item.keywords[ind]){ return true }
if(stext.indexOf(item.keywords[ind])>-1){ return true }
// build answer
function getAnswerFor(item){
// no any answer for admin
let answer = item.answer;
if(!answer){ answer = "" }
answer = answer + "\nhttp://" + item.url
return answer;
// just bust all keywords list
function doSearch(){
let item;
let answer;
for(var ind in list){
item = list[ind];
return getAnswerFor(item);
Functions create your code more simple. It is good for it rewriting and improvement.
Perform searching. And if we get answer - send message:
let answer = doSearch();
Bot.sendMessage(answer, {is_reply: true});
In this command - we have only one Bot.sendMessage function!
It is good - code more simple.
Copy link