Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
TeaBot
allows you to create highly interactive Telegram bots for Node.js with some additional cool features.
/command@BotName
commandsDifference between TeaBot 1.x.x
and TeaBot 2.0.0
here.
$ npm install teabot --save
Simple echo bot:
const TeaBot = require('teabot')('TELEGRAM_BOT_TOKEN', 'TELEGRAM_BOT_NAME');
TeaBot.defineCommand(function (dialog, message) {
dialog.sendMessage('Echo: ' + message.text);
});
TeaBot.startPolling();
TeaBot
based on tg-yarl
(wrapper over Telegram Bot Api with additional features) package, it means TeaBot
inherits all methods from tg-yarl
.
Depending on what type of connection with Telegram is used (webhook
or long polling
), there are 2 methods to start the bot.
To work with webhook
.
To work with long polling
.
Dialog object
stores bot current dialogue with the user
, as well as commands (full list here) for communication.
It can be obtained from the first parameter in defineCommand
and defineAction
callbacks, or directly from TeaBot
object.
Checks whether the user is in a state of action, and if so action name
will be returned, otherwise false
.
Start the action. Then all processes occur in defineAction
callbacks. Action callback will be called at the next incoming message.
defineAction
.Perform the action. Then all processes occur in defineAction
callbacks. Action callback will be called immediately
.
defineAction
.Ends the action and clears dialog.tempData
.
dialog.tempData
will not be cleared.dialog object
methods in docs.Message object
stores processed incoming message, as well as its original copy.
It can be obtained from dialog.message
or from the second parameter in defineCommand
and defineAction
callbacks.
Returns command
or empty string.
It returns the rest of the message, if it contains a command
or the entire message
.
message object
methods in docs.Commands
always starts with /
.
*
to match zero or more characters. A pattern starting with !
will be negated).TeaBot
.defineCommand(['/start', '/help'], function (dialog, message) {
dialog.sendMessage('Hi there. This is a ' + message.getCommand() + ' command.');
})
.defineCommand('/hi*', function (dialog, message) { // wildcard
dialog.sendMessage('This command ' + message.getCommand() + ', starts with /hi');
})
.defineCommand(function (dialog) {
dialog.sendMessage('Send me /help for more information.');
});
You can define some actions
if you want to add interactivity to your bot. Or you want to split your code.
*
to match zero or more characters. A pattern starting with !
will be negated).TeaBot
.defineCommand('/help', function (dialog, message) {
if (message.getArgument()) {
dialog.performAction('/help:1'); // /help argument
} else {
dialog.startAction('/help:2').sendMessage('This is /help command.'); // /help
}
})
.defineCommand(function (dialog) {
dialog.sendMessage('Send me /help for more information.');
});
TeaBot
.defineAction('/help:*', function (dialog) { // wildcard
dialog.endAction().sendMessage('This is ' + dialog.getAction() + ' action'); // if /help was with argument, then /help:1 action, otherwise /help:2
});
*
to match zero or more characters. A pattern starting with !
will be negated).TeaBot
.inlineQuery('tay*', function (query) { // wildcard
query
.addGif(
{ gif_url: 'https://33.media.tumblr.com/tumblr_m3xrtsmgs11rn435g.gif', thumb_url: 'https://33.media.tumblr.com/tumblr_m3xrtsmgs11rn435g.gif', gif_width: 500, gif_height: 247 }
)
.addGif(
{ gif_url: 'http://blog.admissions.illinois.edu/wp-content/uploads/2015/08/Screaming-Taylor-Swift.gif', thumb_url: 'http://blog.admissions.illinois.edu/wp-content/uploads/2015/08/Screaming-Taylor-Swift.gif', gif_width: 480, gif_height: 267 }
)
.answer();
})
.inlineQuery(function (query) {
query
.addArticles([
{ title: 'Test 1', message_text: 'test' },
{ title: 'Test 2', message_text: 'test' },
{ title: 'Test 3', message_text: 'test' }
])
.answer();
});
inline mode
in docs.query object
in docs.At the moment TeaBot
supports only db
and analytics
plugins, but in the future there will be more.
db
or analytics
.const TeaBot = require('teabot')('TELEGRAM_BOT_TOKEN', 'TELEGRAM_BOT_NAME');
TeaBot.use('analytics', require('teabot-botan')('BOTAN_TOKEN'));
TeaBot.defineCommand(function (dialog, message) {
dialog.sendMessage('Echo: ' + message.text); // all message events will be sent directly to botan.io
});
TeaBot.startPolling();
plugins
in docs.By default, no errors are displayed, except for those that may interfere start the bot. But with these methods you be able to handle errors by yourself.
Use this method in Promise
, Callback
functions and whenever you want.
When error occurs or when TeaBot.error()
is used, callback will be invoked.
TeaBot.error()
is called (including internal call).TeaBot.onError(function (e) {
console.error('TeaBot error:', e.stack);
});
TeaBot.defineCommand(function (dialog, message) {
dialog.sendMessage('Echo: ' + message.text).then(function () {
throw new Error('Test error 1');
}).catch(TeaBot.error);
throw new Error('Test error 2');
});
Other examples here.
The MIT License (MIT)
Copyright (c) 2015-2016 Alexey Bystrov
FAQs
TeaBot - a way to build interactive Telegram bots.
The npm package teabot receives a total of 2 weekly downloads. As such, teabot popularity was classified as not popular.
We found that teabot demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.