-
Notifications
You must be signed in to change notification settings - Fork 12
TelegramAPI
Ilya Perkovec edited this page Sep 2, 2016
·
1 revision
Init tg-cli wrapper.
const TelegramAPI = require('tg-cli-node');
const config = require('./config');
// create tg-cli-node instance with configs
const Client = new TelegramAPI(config);
// spawn tg-cli process and connect to socket
Client.connect(connection => {
connection.on('message', msg => {
if (msg.text === 'ping') {
msg.reply('pong')
}
});
connection.on('error', e => {
console.log('Error from Telegram API:', e);
});
connection.on('disconnect', () => {
console.log('Disconnected from Telegram API');
});
});
It creates a new TelegramAPI
with configs
.
const path = require('path');
const TelegramAPI = require('tg-cli-node');
const Client = new TelegramAPI({
telegram_cli_path: path.join(__dirname, 'tg/bin/telegram-cli'),
telegram_cli_socket_path: path.join(__dirname, 'socket'),
server_publickey_path: path.join(__dirname, 'tg/tg-server.pub')
});
-
configs
Object-
telegram_cli_path
String - path to tg-cli -
telegram_cli_socket_path
String - path for socket file -
server_publickey_path
String - path to server key (traditionally, intg/tg-server.pub
)
-
-
callback
Function - called after connecting totg-cli
process withConnection
argument.
Spawn tg-cli
process and connect to him by socket.