telenode-js
Advanced tools
Comparing version 1.0.1-0 to 1.0.1
module.exports = require('./src/bot'); |
{ | ||
"name": "telenode-js", | ||
"version": "1.0.1-0", | ||
"description": "Lightweight Telegram API framework for Node.js", | ||
"main": "index.js", | ||
"author": "Niv Ezra", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "nodemon ./examples", | ||
"publish:dry": "npm publish --dry-run", | ||
"set-webhook": "node ./scripts/setWebhook.js" | ||
}, | ||
"bin": { | ||
"set-webhook": "./scripts/setWebhook.js" | ||
}, | ||
"files": [ | ||
"src/**" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/NivEz/telenode" | ||
}, | ||
"keywords": [ | ||
"telegram", | ||
"telegram bot", | ||
"telegram api", | ||
"telegram bot api", | ||
"telegram framework", | ||
"bot", | ||
"telenode" | ||
], | ||
"dependencies": { | ||
"axios": "^1.2.3", | ||
"express": "^4.18.2" | ||
}, | ||
"devDependencies": { | ||
"nodemon": "^2.0.20", | ||
"dotenv": "^16.0.3" | ||
} | ||
"name": "telenode-js", | ||
"version": "1.0.1", | ||
"description": "Lightweight Telegram API framework for Node.js", | ||
"main": "index.js", | ||
"author": "Niv Ezra <dev@nivezra.com>", | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "nodemon ./scripts/runDev.js", | ||
"publish:dry": "npm publish --dry-run", | ||
"set-webhook": "node ./scripts/setWebhook.js", | ||
"postinstall": "husky install" | ||
}, | ||
"bin": { | ||
"set-webhook": "./scripts/setWebhook.js" | ||
}, | ||
"files": [ | ||
"src/**" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/NivEz/telenode" | ||
}, | ||
"keywords": [ | ||
"telegram", | ||
"telegram bot", | ||
"telegram api", | ||
"telegram bot api", | ||
"telegram framework", | ||
"bot", | ||
"telenode" | ||
], | ||
"dependencies": { | ||
"axios": "^1.2.3", | ||
"express": "^4.18.2" | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^16.0.3", | ||
"husky": "^8.0.3", | ||
"nodemon": "^2.0.20", | ||
"prettier": "^2.8.3", | ||
"pretty-quick": "^3.1.3" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# telenode-js | ||
# Telenode | ||
@@ -6,2 +6,6 @@ | ||
![npm package](https://img.shields.io/badge/-grey?logo=telegram) | ||
[![npm package](https://img.shields.io/npm/v/telenode-js?color=orange&logo=npm)](https://www.npmjs.org/package/telenode-js) | ||
[![MIT licensed](https://img.shields.io/badge/license-MIT-green.svg)](https://raw.githubusercontent.com/NivEz/telenode/main/LICENSE) | ||
--- | ||
@@ -26,3 +30,3 @@ | ||
``` | ||
npm exec set-webhook | ||
npx set-webhook | ||
``` | ||
@@ -33,6 +37,6 @@ | ||
``` | ||
const TeleNode = require('../src/bot'); | ||
const Telenode = require('telenode-js'); | ||
require('dotenv').config(); | ||
const bot = new TeleNode({ | ||
const bot = new Telenode({ | ||
apiToken: process.env.API_TOKEN, | ||
@@ -51,3 +55,13 @@ }); | ||
Additional examples can be found in the [examples folder](https://github.com/NivEz/telenode/tree/main/examples). | ||
Additional examples can be found in the [examples folder](https://github.com/NivEz/telenode/tree/main/examples). | ||
--- | ||
### TODO's | ||
- [x] Regex matching on text messages | ||
- [ ] Buttons support (sending & listening) | ||
- [ ] Direct respond function in message handler without passing chat ID | ||
- [ ] Chat ID handlers | ||
- [ ] Arguments validations | ||
- [ ] Add tests |
@@ -0,0 +0,0 @@ #!/usr/bin/env node |
const { runServer } = require('./server'); | ||
const axios = require('axios'); | ||
class TeleNode { | ||
class Telenode { | ||
#baseUrl; | ||
@@ -9,2 +9,3 @@ | ||
this.textHandlers = {}; | ||
this.arrRegexHandlers = []; | ||
this.anyTextHandler = null; | ||
@@ -19,9 +20,24 @@ this.#baseUrl = 'https://api.telegram.org/bot' + apiToken; | ||
messageHandler(receivedMessage) { | ||
if (receivedMessage.text) { | ||
const textHandler = this.textHandlers[receivedMessage.text]; | ||
if (textHandler) { | ||
textHandler(receivedMessage); | ||
} else if (this.anyTextHandler) { | ||
this.anyTextHandler(receivedMessage); | ||
const msg = receivedMessage.text; | ||
if (!msg) { | ||
return; | ||
} | ||
const textHandler = this.textHandlers[msg]; | ||
if (textHandler) { | ||
textHandler(receivedMessage); | ||
return; | ||
} | ||
this.arrRegexHandlers.some(re => { | ||
const isMatch = msg.match(re.pattern); | ||
if (isMatch) { | ||
re.handler(receivedMessage); | ||
// Return true to stop the loop | ||
return true; | ||
} | ||
}); | ||
// This should be the final step to validate that no matches occurred | ||
if (this.anyTextHandler) { | ||
this.anyTextHandler(receivedMessage); | ||
return; | ||
} | ||
@@ -33,5 +49,11 @@ }; | ||
this.anyTextHandler = handler; | ||
} else { | ||
} else if (message instanceof RegExp) { | ||
this.arrRegexHandlers.push({ | ||
pattern: message, | ||
handler, | ||
}); | ||
} else if (typeof message === 'string') { | ||
this.textHandlers[message] = handler; | ||
} | ||
}; | ||
@@ -48,2 +70,3 @@ | ||
module.exports = TeleNode; | ||
module.exports = Telenode; | ||
@@ -0,0 +0,0 @@ const express = require('express'); |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5938
7
100
1
64
5
1