@ChanMbot Part2

In our last post we create bot that does nothing so now we need to add some commands.

After //:

All bots starts with /start

bot.on([‘/start’], (msg, self) => {
const replyMarkup = bot.inlineKeyboard([
[
bot.inlineButton(‘Help’, {callback: ‘/help’})
],
]);

let id = msg.chat.id;
let replyToMessage = msg.message_id;
let type = self.type;
let parseMode = ‘markdown’;
return bot.sendMessage(
id, `Hi! I’m *Channel Manager bot*! [ChanM](http://t.me/ChanMbot)
Type /help for more
follow @MrCyjaneKbots.`, {replyToMessage, replyMarkup, parseMode}
);
});

If you want to change this message you can use markdown:

*bold text*
_italic text_
[inline URL](http://www.example.com/)
[inline mention of a user](tg://user?id=123456789)

Ok then:

bot.on([‘/help’], (msg, self) => {
const replyMarkup = bot.inlineKeyboard([
[
bot.inlineButton(‘Markdown Help’, {callback: ‘/markdown’})
],
[
bot.inlineButton(‘ID’, {callback: ‘/’})
],
[
bot.inlineButton(‘PM: @BotDev’, {callback: ‘/brb’})
],
]);
let id = msg.from.id;
let replyToMessage = msg.message_id;
let type = self.type;
let parseMode = ‘markdown’;
return bot.sendMessage(
id, `*Help Menu*
*1.* I can /markdown [and /html soon] messages
*2.* I can give you /id of chat (priv, group, supergroup, channel)
*3.* I can manage your channel! just:
– Add me as admin to your channel
– send me any _/md *Markdown*_ message
– bot will delete your message and send better one 😉
– contact me: @BotDev`, {replyToMessage, replyMarkup, parseMode}
);
});

Now markdown help menu:

bot.on([‘/markdown’], (msg, self) => {
let id = msg.chat.id;
let replyToMessage = msg.message_id;
let type = self.type;
let parseMode = ‘html’;
return bot.sendMessage(
id, `/markdown *Help Menu*
1. <b> Bold text </b>
code: *Bold text*
2. <i> Italic text </i>
code: _Italic text_
3. <a href=”http://www.example.com/”>inline URL</a>
code: [inline URL](http://www.example.com)
4. <code> code text </code>
code: <a href=”https://t.me/joinchat/AAAAAEhOMb2CNb7Mdq9w9w”>Check Code Here</a>

If you have your message type <code>/md message text here </code>

<b>Remember! Telegram remove messages with invalid markdown so look for double [,(,),],*,_ etc..</b>
`, {replyToMessage, parseMode}
);
});

/md command

bot.on([‘/md’], (msg, self) => {
let id = msg.chat.id;
let replyToMessage = msg.message_id;
let message = msg.text.replace(‘/md ‘, ”);
let type = self.type;
let parseMode = ‘markdown’;
return bot.sendMessage(
id, `${ message }`, {parseMode}
);
});

bot.on([‘/md’], (msg, self) => {
let id = msg.chat.id;
let mssg = msg.message_id;
return bot.deleteMessage(id, mssg)

});

/Id command

bot.on([‘/id’], (msg, self) => {
let id = msg.chat.id;
let replyToMessage = msg.message_id;
let usernamee = msg.chat.username;
let type = self.type;
let parseMode = ‘markdown’;
return bot.sendMessage(
id, `*Read this:*
Chat ID: *${ id }*
Message ID: *${ replyToMessage }*
@name: @${ usernamee }
t.me link: http://t.me/${ usernamee }
(undefined mean that this chat doesn’t have any @name)
telegram link: [${ usernamee }](tg://user?id=${ id })`, {replyToMessage, parseMode}
);
});

Oh also we need to log all messages to consle

// Log every text message
bot.on(‘text’, function (msg) {
console.log(`[text] ${ msg.chat.id } ${ msg.text }`);
});

End for now

Join @AntiMany

Live demo @ChanMBot

One Reply to “@ChanMbot Part2”

Leave a Reply

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