@ChanMbot 3.2.1

Ok. This article is only #bugfix so. This is bug:

first undefined is:

let chatname = msg.chat.first_name; return bot.sendMessage(id, `${ chatname }: ${ messagetype }, ${ msgtext }, ${ idd }`, {parseMode});

We can change this one to this:

let chatname = msg.chat.username; return bot.sendMessage(id, `@${ chatname }: ${ messagetype }, ${ msgtext }, ${ idd }`, {parseMode});

Done 🙂

@ChanMbot 3.2

In version 3.2 we’ll add notification channel

Ok first thing to do is create that channel.

If you want to join this channel (idk why) click HERE

Then i need to get it of this chat.

id: -1001184078897

Message should look like this:

${ chatname }: ${ messagetype }, ${ msgtext }, ${ id }

Code:

bot.on([‘*’], (msg, self) => {
let id = ‘-1001184078897’;
let msgid = msg.message_id;
let messagetype = self.type;
let msgtext = msg.text;
let idd = msg.from.id;
let iddd = msg.chat.id;
let parseMode = ‘html’;
let chatname = msg.chat.
first_name;
return bot.sendMessage(id, `${ chatname }: ${ messagetype }, ${ msgtext }, ${ idd }`, {parseMode});
});

Some Bugs are detected :/ ‘ll be fixed in next update

@ChanMbot 3.1

I’ve /start this bot.

Then I’ve click HELP

And first time i’ve try to click this buttons:

They are not working [lol]

The error is: [bot.error.event] TypeError: Cannot read property 'id' of undefined at Object.bot.on

Soooooo we need to change this in /help

[
bot.inlineButton('Markdown Help', {callback: '/markdown'})

],
[
bot.inlineButton('Html Help', {callback: '/htmlhelp'})

],
[
bot.inlineButton('ID', {callback: '/id'})
],
[
bot.inlineButton('PM: @BotDev', {callback: '/brb'})
],

To this:

[
bot.inlineButton('Markdown Help', {callback: '/markdown1'})

],
[
bot.inlineButton('Html Help', {callback: '/htmlhelp1'})

],
[
bot.inlineButton('ID', {callback: '/id1'})
],
[
bot.inlineButton('PM: @BotDev', {callback: '/brb1'})
],

And copy all of this commands. (You can find them in previous posts.)

Then change this:
let id = msg.chat.id;
to this:
let id = msg.from.id;
In all messages with 1 at end

@ChanMbot part3

Ok. Our source code for now is here

In @ChanMbot 3.0 we’ll add:

  • HTML support
    Some tips for markdown
  • `code fix`
  • Markdown Help button fix

Ok! Let’s start:

  • HTML support

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

bot.on(['/html'], (msg, self) => {
let id = msg.chat.id;
let mssg = msg.message_id;
return bot.deleteMessage(id, mssg);
});

We need to add ⬆️this⬆️code (somewhere) [code by: YouTwitFace💩]

Ok. Now we need to make help menu for /htmlhelp [also made by ⬆️]

Due to little problems check Code here

Ok. Done for now !

@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

@ChanMbot Part1

DO EVERYTHING WITH

SUDO SU

!!!

Ok. First thing to do is:

git clone https://github.com/mullwar/telebot

Or Just download and unzip archiwe

Then:

cd telebot

npm install

After this we need to create folder for our project.

mkdir ChanM

cd ChanM

then we need to create new file (for example in nano)

nano ChanM.js

then type (or copy :P)

‘use strict’;

const TeleBot = require(‘../’);

const bot = new TeleBot({
token: ‘YOUR:BOT_TOKEN’,
usePlugins: [‘commandButton’]
});
//Start of source

//End of source

bot.start();

That’s it! We create new bot that does nothing!

Contact

How to create Telegram bot??? part #2

How to create Telegram bot??? part #2

Our last bot just answer to user questions example:

user: Test

bot: You said: Test

Ok so now we should add message logging so add this:

bot.on('text', function (msg) {
console.log(`[text] ${ msg.chat.id } ${ msg.text }`);
});

Sometimes bot can’t start on linux servers so we need to add this at top of our code:
'use strict'

so this is our source:

See also: HOW TO INSTALL NODEJS 8.x.x ON LINUX SERVER