telenode-js
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "telenode-js", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Lightweight Telegram API framework for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -97,2 +97,4 @@ # Telenode | ||
For local development you should spin up a local express server with the command `bot.createServer()`. More on that will be explained in the <b>Deployment</b> section down below. | ||
The webhook url should be presented in the `.env` file or be exported as an environment variable. | ||
@@ -107,2 +109,27 @@ | ||
--- | ||
## Deployment: | ||
Since these days it is common to use serverless backend services, you can choose how the bot will work - or with `express` or with the `HTTP` engine of the serverless provider. | ||
In order to spin up an express server you should use the command `bot.createServer()` - this is useful for deployments on VMs / containers / on-premise. | ||
You can pass an object as options for `createServer`. Currently, it supports `port` and `unauthorizedCallback` (if you use secret token) - e.g: | ||
``` | ||
bot.createServer({ port: 4000 }) // the default is 3000 | ||
``` | ||
In the other hand, if you want to deploy on serverless backend you need to use `bot.telenodeHandler` method and pass to it the request object. | ||
You will probably have something like this: | ||
``` | ||
functions.https.onCall((req, res) => { | ||
const secretToken = req.headers['x-telegram-bot-api-secret-token']; | ||
bot.telenodeHandler(req.body, secretToken, unauthorizedHandler); | ||
res.end(); | ||
}); | ||
``` | ||
Note that on serverless you should extract by your own the `secretToken` since every serverless service might process the `req` object differently. | ||
## TODO's | ||
@@ -109,0 +136,0 @@ |
@@ -17,5 +17,5 @@ const { runServer } = require('./server'); | ||
createServer(unauthorizedHandler) { | ||
this.unauthorizedHandler = unauthorizedHandler; | ||
runServer(this); | ||
createServer({ port, unauthorizedCallback } = {}) { | ||
this.unauthorizedHandler = unauthorizedCallback; | ||
runServer(this, port); | ||
} | ||
@@ -22,0 +22,0 @@ |
const express = require('express'); | ||
const server = express(); | ||
const port = 3000; | ||
const runServer = bot => { | ||
const runServer = (bot, port = 3000) => { | ||
server.use(express.json()); | ||
@@ -7,0 +6,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11196
142
179