Huge News!Announcing our $40M Series B led by Abstract Ventures.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.4.4 to 0.5.0

lib/memory-session.js

7

package.json
{
"name": "telegraf",
"version": "0.4.4",
"version": "0.5.0",
"description": "Telegram bot framework",
"main": "lib/app.js",
"main": "lib/telegraf.js",
"repository": {

@@ -29,3 +29,4 @@ "type": "git",

"files": [
"lib/app.js"
"lib/telegraf.js",
"lib/memory-session.js"
],

@@ -32,0 +33,0 @@ "scripts": {

@@ -5,3 +5,3 @@ # Telegraf

Telegram bot framework for node.js
Modern Telegram bot framework for node.js

@@ -19,6 +19,6 @@ ## Installation

var app = new Telegraf(process.env.BOT_TOKEN);
var telegraf = new Telegraf(process.env.BOT_TOKEN);
// Text messages handling
app.hears('/answer', function * () {
telegraf.hears('/answer', function * () {
this.reply('*42*', { parse_mode: 'Markdown' })

@@ -34,7 +34,7 @@ })

// Wow! RegEx
app.hears(/reverse (.+)/, sayYoMiddleware, function * () {
telegraf.hears(/reverse (.+)/, sayYoMiddleware, function * () {
this.reply(this.match[1].split('').reverse().join(''))
})
app.startPolling()
telegraf.startPolling()
```

@@ -57,9 +57,9 @@

var Telegraf = require('telegraf')
var app = new Telegraf(process.env.BOT_TOKEN)
var telegraf = new Telegraf(process.env.BOT_TOKEN)
app.on('text', function * (){
telegraf.on('text', function * (){
this.reply('Hello World')
})
app.startPolling()
telegraf.startPolling()
```

@@ -82,6 +82,6 @@

```js
var app = new Telegraf(process.env.BOT_TOKEN)
var telegraf = new Telegraf(process.env.BOT_TOKEN)
// Logger middleware
app.use(function * (next){
telegraf.use(function * (next){
var start = new Date

@@ -94,3 +94,3 @@ this.state.started = start

app.on('text', function * (){
telegraf.on('text', function * (){
this.reply('Hello World')

@@ -106,3 +106,3 @@ })

```js
app.use(function * (){
telegraf.use(function * (){
this.telegraf // Telegraf instance

@@ -137,5 +137,5 @@ this.eventType // Event type

```js
var app = new Telegraf(process.env.BOT_TOKEN)
var telegraf = new Telegraf(process.env.BOT_TOKEN)
app.use(function * (next) {
telegraf.use(function * (next) {
this.state.role = getUserRole(this.message)

@@ -145,6 +145,24 @@ yield next

app.on('text', function * (){
telegraf.on('text', function * (){
this.reply(`Hello ${this.state.role}`)
})
```
## Session
For development you can use `Telegraf.memorySession()`, but session will be lost on app restart.
For production environment use any [`telegraf-session-*`](https://www.npmjs.com/search?q=telegraf-session) middleware.
```js
var telegraf = new Telegraf(process.env.BOT_TOKEN)
telegraf.use(Telegraf.memorySession())
telegraf.on('text', function * (){
this.session.counter = this.session.counter || 0
this.session.counter++
this.reply(`Message counter:${this.session.counter}`)
})
```
## Error Handling

@@ -156,3 +174,3 @@

```js
app.onError = function(err){
telegraf.onError = function(err){
log.error('server error', err)

@@ -169,4 +187,5 @@

* [`new Telegraf(token)`](#new)
* [`.setWebHook(url, cert)`](#setwebhook)
* [`.startWebHook(path, tlsOptions, port, [host])`](#startWebHook)
* [`.startPolling(timeout, limit)`](#startPolling)
* [`.startWebHook(token, tlsOptions, port, [host])`](#startWebHook)
* [`.stop()`](#stop)

@@ -190,3 +209,2 @@ * [`.use(function)`](#use)

* [`.getFileLink(fileId)`](#getFileLink)
* [`.setWebHook(url, cert)`](#setwebhook)
* [`.removeWebHook()`](#removewebhook)

@@ -204,3 +222,3 @@ * [`.kickChatMember(chatId, userId)`](#kickchatmember)

Initialize new app.
Initialize new Telegraf app.

@@ -211,14 +229,16 @@ | Param | Type | Description |

* * *
<a name="startPolling"></a>
#### `Telegraf.startPolling(timeout, limit)`
<a name="setwebhook"></a>
#### `Telegraf.setWebHook(url, [cert])` => `Promise`
Start poll updates.
Specifies an url to receive incoming updates via an outgoing webHook.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| timeout | `Int` | 0 | Poll timeout |
| limit | `Int` | 100 | Limits the number of updates to be retrieved |
| Param | Type | Description |
| --- | --- | --- |
| url | `String` | Public url for webhook |
| cert | [`File`](#file) | SSL public certificate |
[Related Telegram api docs](https://core.telegram.org/bots/api#setwebhook)
* * *

@@ -233,3 +253,3 @@

| --- | --- | --- |
| token | `String` | Token |
| path | `String` | Url path (see Telegraf.setWebHook) |
| tlsOptions | `Object` | [tls server options](https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener) |

@@ -241,2 +261,14 @@ | port | `Int` | Port number |

<a name="startPolling"></a>
#### `Telegraf.startPolling(timeout, limit)`
Start poll updates.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| timeout | `Int` | 0 | Poll timeout |
| limit | `Int` | 100 | Limits the number of updates to be retrieved |
* * *
<a name="stop"></a>

@@ -471,15 +503,2 @@ #### `Telegraf.stop()`

<a name="setwebhook"></a>
#### `Telegraf.setWebHook(url, [cert])` => `Promise`
Specifies an url to receive incoming updates via an outgoing webHook.
| Param | Type | Description |
| --- | --- | --- |
| url | `String` | File id |
| cert | [`File`](#file) | SSL public certificate |
[Related Telegram api docs](https://core.telegram.org/bots/api#setwebhook)
* * *
<a name="removewebhook"></a>

@@ -653,3 +672,3 @@ #### `Telegraf.removeWebHook()` => `Promise`

// Handle stickers and photos
app.on(['sticker', 'photo'], function * () {
telegraf.on(['sticker', 'photo'], function * () {
console.log(this.message)

@@ -660,3 +679,3 @@ this.reply('Cool!')

// Handle all messages except `inline_query`, `chosen_inline_result` and `callback_query`
app.on('message', function * () {
telegraf.on('message', function * () {
this.reply('Hey there!')

@@ -674,7 +693,7 @@ })

```js
var app = new Telegraf(process.env.BOT_TOKEN)
var telegraf = new Telegraf(process.env.BOT_TOKEN)
app.on('text', function * (){
telegraf.on('text', function * (){
// Simple usage
app.sendMessage(this.message.chat.id, `Hello ${this.state.role}`)
telegraf.sendMessage(this.message.chat.id, `Hello ${this.state.role}`)

@@ -689,11 +708,11 @@ // Using shortcut

* `reply()` -> `app.sendMessage()`
* `replyWithPhoto()` -> `app.sendPhoto()`
* `replyWithAudio()` -> `app.sendAudio()`
* `replyWithDocument()` -> `app.sendDocument()`
* `replyWithSticker()` -> `app.sendSticker()`
* `replyWithVideo()` -> `app.sendVideo()`
* `replyWithVoice()` -> `app.sendVoice()`
* `replyWithChatAction()` -> `app.sendChatAction()`
* `replyWithLocation()` -> `app.sendLocation()`
* `reply()` -> `telegraf.sendMessage()`
* `replyWithPhoto()` -> `telegraf.sendPhoto()`
* `replyWithAudio()` -> `telegraf.sendAudio()`
* `replyWithDocument()` -> `telegraf.sendDocument()`
* `replyWithSticker()` -> `telegraf.sendSticker()`
* `replyWithVideo()` -> `telegraf.sendVideo()`
* `replyWithVoice()` -> `telegraf.sendVoice()`
* `replyWithChatAction()` -> `telegraf.sendChatAction()`
* `replyWithLocation()` -> `telegraf.sendLocation()`

@@ -700,0 +719,0 @@ ## License

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