-
Notifications
You must be signed in to change notification settings - Fork 12
Connection
Ilya Perkovec edited this page Sep 2, 2016
·
4 revisions
Client.connect(connection => {
connection.on('message', msg => {
if (msg.text === 'ping') {
msg.reply('pong') // or connection.reply(msg.id, 'pong')
}
});
connection.on('error', e => {
console.log('Error from Telegram API:', e);
});
connection.on('disconnect', () => {
console.log('Disconnected from Telegram API');
});
});
-
peer
String -
message
String
connection.on('message', msg => {
connection.send(msg.to.print_name, 'pong');
});
Send message
to peer
.
-
peer
String -
message_id
String
connection.on('message', msg => {
connection.forward(msg.to.print_name, msg.id);
});
Forward message by message_id
to peer
.
-
reply_id
String -
message
String
connection.on('message', msg => {
connection.reply(msg.id, 'pong');
});
Reply to message by id with message
.
-
message_id
String
connection.on('message', msg => {
connection.deleteMsg(msg.id);
});
Delete message by message_id
.
-
peer
String -
path
String
connection.on('message', msg => {
connection.sendImage(msg.to.print_name, 'telegram.png');
});
Send image from path
to peer
.
-
peer
String -
path
String
connection.on('message', msg => {
connection.sendDocument(msg.to.print_name, 'telegram.txt');
});
Send document from path
to peer
.
-
peer_id
String
connection.on('message', msg => {
connection.userInfo(msg.from.id).then(data => {
console.log(data)
});
});
Get info about user by peer_id
.
Returns:
-
Promise
=>Peer
[]
connection.on('message', msg => {
if (msg.text === 'ping') {
connection.contactList().then(data => {
console.log(data[0]);
});
}
});
Get contact list.
Returns:
-
Promise
=>Peer
[]
connection.on('message', msg => {
if (msg.text === 'ping') {
connection.dialogList().then(data => {
console.log(data[0]);
});
}
});
Get dialog list.
Returns:
-
message
Message
Emitted when Connection
close connection with tg-cli
process.
Returns:
- 'error' Object
Emitted when handled error.