botyscaphe-tg
v1.1.1
Published
Telegram Bot Api implementation by MadBrozzeR
Readme
Botyscaphe-TG
This is yet another implimentation of Telegram Bot API. It can be used inside JavaScript/TypeScript application, or from command line.
How to start
Install dependency with npm i botyscaphe-tg command (or using package manager of your choice).
How to use in TypeScript/JavaScript
- Initialize bot using your bot token and secret string, if it exists
import { Bot } from 'botyscaphe-tg';
const tgBot = new Bot({
token: 'yourbottoken:1234567',
secret: 'optional string provided as secret to BotFather',
});- Send commands and messages
// Send data to Bot API.
tgBot.useMethod('sendMessage', { chat_id: <chat-id>, text: 'Hello, world!' });
If you use TypeScript, helpers for both arguments should be accessible, just use TypeScript
features to investigate. Also if method does not require data to send (like getMe or logOut),
second argument should be omitted.
If this library is outdated, and required method is not yet implemented, you can use this method, but, obviously, type helpers won't work.
tgBot.sendRaw('notImplementedMethod', '{"some": "data to send"}');- Listen to updates on server
import http from 'https';
https.createServer(function (request, response) {
tgBot.getFromRequest(request).then((update) => {
// Do something with received update
console.log(update);
// Do not forget to send back a response
response.writeHead(204);
response.end();
}).catch(console.error)
}).listen(8080);How to use from command line
- In order to use command line tool, create and edit
.bot.jsonfile that should look like this:
{
"token": "yourbottoken:1234567"
}Consider your token privacy by .gitignore-ing this file.
- Run
npx botyscaphe-launch <method> [<data>]command
$ npx botyscaphe-launch getMe
{
.......
}
$ npx botyscaphe-launch sendMessage '{"chat_id":0,"text":"Hello, world!"}'
{
.......
}Note that data should be wrapped in single or double quotes, so similar quotes inside data must be escaped.
Either response or error from Bot API will be displayed.
