New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

telegraf

Package Overview
Dependencies
Maintainers
1
Versions
241
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegraf - npm Package Compare versions

Comparing version 0.9.3 to 0.9.4

14

lib/memory-session.js

@@ -7,11 +7,5 @@ var debug = require('debug')('telegraf:session-memory')

opts = Object.assign({
getSessionKey: function (event) {
var chatId = 'global'
if (event.chat) {
chatId = event.chat.id
}
if (event.message && event.message.chat) {
chatId = event.message.chat.id
}
return `${event.from.id}:${chatId}`
getSessionKey: function (ctx) {
debug(ctx)
return `${ctx.from.id}:${ctx.chat.id}`
}

@@ -21,3 +15,3 @@ }, opts)

return function * (next) {
var key = opts.getSessionKey(this.message || this.callbackQuery || this.inlineQuery || this.chosenInlineResult)
var key = opts.getSessionKey(this)
if (!key) {

@@ -24,0 +18,0 @@ return yield next

@@ -70,15 +70,15 @@ var debug = require('debug')('telegraf:core')

/**
* Generates `middleware` for handling provided event types.
* Generates `middleware` for handling provided update types.
*
* @param {string|string[]} eventTypes
* @param {string|string[]} updateTypes
* @param {(GeneratorFunction|GeneratorFunction[])} fn - middleware
* @api public
*/
Telegraf.handler = function (eventTypes) {
if (typeof eventTypes === 'string') {
eventTypes = [eventTypes]
Telegraf.handler = function (updateTypes) {
if (typeof updateTypes === 'string') {
updateTypes = [updateTypes]
}
var fns = [].slice.call(arguments, 1)
return function * (next) {
if (eventTypes.indexOf(this.eventType) !== -1 || eventTypes.indexOf(this.eventSubType) !== -1) {
if (updateTypes.indexOf(this.updateType) !== -1 || updateTypes.indexOf(this.updateSubType) !== -1) {
yield Telegraf.compose(fns)

@@ -219,5 +219,5 @@ }

/**
* Use the given middleware as handler for `eventType`.
* Use the given middleware as handler for `updateType`.
*
* @param {string} eventType - Event type
* @param {string} updateType - Update type
* @param {(GeneratorFunction|GeneratorFunction[])} fn - middleware

@@ -227,5 +227,5 @@ * @return {Telegraf} self

*/
telegraf.on = function (eventTypes) {
telegraf.on = function (updateTypes) {
var fns = [].slice.call(arguments, 1)
this.use(Telegraf.handler(eventTypes, Telegraf.compose(fns)))
this.use(Telegraf.handler(updateTypes, Telegraf.compose(fns)))
return this

@@ -648,3 +648,2 @@ }

/**

@@ -903,8 +902,17 @@ * Use this method to unban a previously kicked user in a supergroup.

}
debug('⚡ update', update.type, update.subType || '--')
debug('⚡ update', update.type, update.subType || '-')
var chat = { id: '-' }
if (update.chat) {
chat = update.chat
}
if (update.message && update.message.chat) {
chat = update.message.chat
}
var state = {}
var context = Object.assign({
telegraf: this,
eventType: update.type,
eventSubType: update.subType,
updateType: update.type,
updateSubType: update.subType,
chat: chat || {},
from: update.from || {},
state: state

@@ -911,0 +919,0 @@ }, this.context)

{
"name": "telegraf",
"version": "0.9.3",
"version": "0.9.4",
"description": "📢 Modern Telegram bot framework",

@@ -5,0 +5,0 @@ "main": "lib/telegraf.js",

@@ -124,13 +124,15 @@ [![npm](https://img.shields.io/npm/l/telegraf.svg?style=flat-square)](https://www.npmjs.com/package/telegraf)

```js
telegraf.use(function * (){
this.telegraf // Telegraf instance
this.eventType // Event type(message, inline_query, etc.)
this.eventSubType // Event subtype(text, sticker, audio, etc.)
this.message // Received message
this.editedMessage // Edited message
this.inlineQuery // Received inline query
this.chosenInlineResult // Received inline query result
this.callbackQuery // Received callback query
this.match // Regex match (available only for `hears` handler)
});
telegraf.use(function * () {
this.telegraf // Telegraf instance
this.updateType // Update type(message, inline_query, etc.)
[this.updateSubType] // Update subtype(text, sticker, audio, etc.)
[this.message] // Received message
[this.editedMessage] // Edited message
[this.inlineQuery] // Received inline query
[this.chosenInlineResult] // Received inline query result
[this.callbackQuery] // Received callback query
[this.chat] // Current chat info
[this.from] // Sender info
[this.match] // Regex match (available only for `hears` handler)
})
```

@@ -153,2 +155,52 @@

### Update types
Supported update types:
- `message`
- `edited_message`
- `inline_query`
- `chosen_inline_result`
- `callback_query`
Available update sub-types:
- `text`
- `audio`
- `document`
- `photo`
- `sticker`
- `video`
- `voice`
- `contact`
- `location`
- `venue`
- `new_chat_member`
- `left_chat_member`
- `new_chat_title`
- `new_chat_photo`
- `delete_chat_photo`
- `group_chat_created`
- `supergroup_chat_created`
- `channel_chat_created`
- `migrate_to_chat_id`
- `migrate_from_chat_id`
- `pinned_message`
```js
// Handle message update
telegraf.on('message', function * () {
this.reply('Hey there!')
})
// Handle sticker update
telegraf.on(['sticker', 'photo'], function * () {
console.log(this.message)
this.reply('Cool!')
})
```
<sub>[Related Telegram api docs](https://core.telegram.org/bots/api#message)</sub>
### State

@@ -260,3 +312,3 @@

**message** event:
**message** update:

@@ -278,3 +330,3 @@ - `getChat() -> `[`telegraf.getChat()`](#getchat)

**callback_query** event:
**callback_query** update:

@@ -297,3 +349,3 @@ - `answerCallbackQuery() -> `[`telegraf.answerCallbackQuery()`](#answercallbackquery)

**inline_query** event:
**inline_query** update:

@@ -391,9 +443,9 @@ - `answerInlineQuery() -> `[`telegraf.answerInlineQuery()`](#answerinlinequery)

<a name="handler"></a>
##### `Telegraf.handler(eventType, handler, [handler...]) => GeneratorFunction`
##### `Telegraf.handler(updateType, handler, [handler...]) => GeneratorFunction`
Generates middleware for handling provided [event type](#events).
Generates middleware for handling provided [update type](#update-types).
| Param | Type | Description |
| --- | --- | --- |
| eventType | `string`\|`string[]` | [Event type](#events) |
| updateType | `string`\|`string[]` | [update type](#update-types) |
| handler | `GeneratorFunction` | Handler |

@@ -627,3 +679,3 @@

Registers handler only for `text` events using string pattern or RegEx.
Registers handler only for `text` updates using string pattern or RegEx.

@@ -666,9 +718,9 @@ | Param | Type | Description |

<a name="on"></a>
##### `.on(eventType, handler, [handler...])`
##### `.on(updateType, handler, [handler...])`
Registers handler for provided [event type](#events).
Registers handler for provided [update type](#update-types).
| Param | Type | Description |
| --- | --- | --- |
| eventType | `string`\|`string[]` | [Event type](#events) |
| updateType | `string`\|`string[]` | [update type](#update-types) |
| handler | `GeneratorFunction` | Handler |

@@ -943,51 +995,2 @@

### Events
Supported event:
- `message`
- `inline_query`
- `chosen_inline_result`
- `callback_query`
Available virtual events:
- `text`
- `audio`
- `document`
- `photo`
- `sticker`
- `video`
- `voice`
- `contact`
- `location`
- `venue`
- `new_chat_member`
- `left_chat_member`
- `new_chat_title`
- `new_chat_photo`
- `delete_chat_photo`
- `group_chat_created`
- `supergroup_chat_created`
- `channel_chat_created`
- `migrate_to_chat_id`
- `migrate_from_chat_id`
- `pinned_message`
```js
// Handle all messages
telegraf.on('message', function * () {
this.reply('Hey there!')
})
// Handle virtual events
telegraf.on(['sticker', 'photo'], function * () {
console.log(this.message)
this.reply('Cool!')
})
```
<sub>[Related Telegram api docs](https://core.telegram.org/bots/api#message)</sub>
## License

@@ -994,0 +997,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc