Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
lambda-telegram-bot-handler
Advanced tools
Library to build and run Telegram bots in AWS Lambda platform
Library to build and run Telegram bots in AWS Lambda platform. It works using the webhook option of the Telegram bot API (https://core.telegram.org/bots/api#getting-updates), and the AWS API Gateway.
The library exports a method to easily handle Lambda invocations from Telegram acording to your specified filters.
var telegramHandler = require('lambda-telegram-bot-handler');
exports.handler = telegramHandler({
onText: [
{
matches: /^\/pattern$/,
handler: function (msg, cb) {
// process and answer message here
cb();
}
},
{
matches: /^\/pattern2 (.+)$/,
handler: function (msg, cb, matches) {
// process and answer message here
// `matches` will have the result of "message".match(/^\/pattern2 (.+)$/)
cb();
}
}
],
onMessage: function (msg, cb) {
// process and answer message here
cb();
}
});
exports.handler
is the handler you specify in your Lambda function configuration. So it's the method that will be called on each Lambda invocation.
Only one message handler function will be called for each invocation, so onText
handlers take precedence over onMessage
, and among onText
handlers, the first that matches the message text (in declaration order) will be called.
In the example above, if a user sends the message /pattern
, the first handler in the onText
array will be called. If the user sends /pattern2 hello
, the second handler will be called. And finally if the user sends /no_match
, the onMessage
handler will be called.
telegramHandler(opts)
Returns a Lambda handler function: function (event, context) { ... }
opts
is an object where you define the message handlers. It has the following properties:
onText
(array of objects - optional): array of text message handlers. Handlers defined in this array will only process text messages (see https://core.telegram.org/bots/api#message) that match the defined regex. They are defined as an object with the following attributes:
matches
(regex - mandatory): the regular expression that the message has to matchhandler
(function - mandatory): the actual message handleronLocation
(function - optional): location message handler.onMessage
(function - optional): fallback message handler. This function will be called for each message received that hasn't been handled by any other defined handlers.onInlineQuery
(function - optional): handler for inline queries (https://core.telegram.org/bots/api#inlinequery)onChosenInlineResult
(function - optional): handler for choosen inline query results (https://core.telegram.org/bots/api#choseninlineresult)These are your defined functions to handle Telegram messages. They receive the following arguments:
msg
: the actual telegram messagecallback
: function to be called when the handler has finished processing the message. NOTE: This callback ends the execution of the Lambda function, so make sure to always call it to avoid unnecessary extra running time.matches
: the result of executing regexp.exec on the message text. Will only be present for onText
handlers as they run against a regexp.To run a bot on AWS Lambda you just need 3 things:
https://123456abc.execute-api.eu-west-1.amazonaws.com/prod/
)MIT
FAQs
Library to build and run Telegram bots in AWS Lambda platform
We found that lambda-telegram-bot-handler 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.