@ChanMBot 5.0

In this update we will add a /feedback command and a /send to reply.

First we will add /feedback:

bot.on(['/feedback'], (msg) => {
 let id = msg.from.id;
 let replyToMessage = msg.message_id;
 let replyMarkup = 'reply';

return bot.sendMessage(id, `Please send your feedback`, {replyToMessage, ask: 'feedback', replyMarkup});
});

bot.on(['ask.feedback'], (msg) => {
 let id = msg.from.id;
 let replyToMessage = msg.message_id;
 let parseMode = 'markdown';

if (msg.text == '/cancel') {
 return bot.sendMessage(id, "I've canceled that!", {replyToMessage});
 } else {
 return bot.sendMessage(id, `Thanks for the feedback`, {replyToMessage}), bot.sendMessage(YOUR_ID, `[${msg.from.username}](tg://user?id=${id}) (\`${id}\`):\n\n${msg.text}`, {parseMode});
 } 
});

and replace YOUR_ID with your id.

 

Next we will add /send:

let send, send_message;

bot.on(['/send'], (msg) => {
 let id = msg.from.id;
 let replyToMessage = msg.message_id;

if (id === YOUR_ID && msg.text == '/cancel') {
 return bot.sendMessage(id, "I've canceled that");
 } else if (id === YOUR_ID && msg.text != '/cancel') {
 return bot.sendMessage(msg.from.id, `Who would you like to send a message to?`, {replyToMessage, ask: 'send_id'});
 }
});

bot.on(['ask.send_id'], (msg) => {
 let id = msg.from.id;
 let replyToMessage = msg.message_id;

if (id === YOUR_ID && msg.text == '/cancel') {
 return bot.sendMessage(id, "I've canceled that");
 } else if (id === YOUR_ID && msg.text != '/cancel') {
 return bot.sendMessage(id, `What would you like to send?`, {replyToMessage, ask: 'send_msg'}).then(() => send = `${msg.text}`).then(() => console.log(send));
 }
});

bot.on(['ask.send_msg'], (msg) => {
 let id = msg.from.id;
 let replyToMessage = msg.message_id;

if (id === YOUR_ID && msg.text == '/cancel') {
 return bot.sendMessage(id, "I've canceled that");
 } else if (id === YOUR_ID && msg.text != '/cancel') {
 return bot.sendMessage(id, `What would you like to send?`, {replyToMessage}).then(() => send_message = `${msg.text}`).then(() => console.log(send_message)).then(() => bot.sendMessage(send, `Message from the admin:\n\n${send_message}`));
 }
});

and again replace YOUR_ID with your id.

Leave a Reply

Your email address will not be published. Required fields are marked *