first commit

This commit is contained in:
borovlioff
2023-09-09 00:11:17 +03:00
commit 9c23f9ba86
22 changed files with 2547 additions and 0 deletions

36
sample/get-entity.js Normal file
View File

@@ -0,0 +1,36 @@
module.exports = function (RED) {
function GetEntity(config) {
RED.nodes.createNode(this, config);
this.config = RED.nodes.getNode(config.config);
var node = this;
this.on('input', async function (msg) {
const input = msg.payload.input || config.input;
/** @type {TelegramClient} */
const client = msg.payload?.client ? msg.payload.client : this.config.client;
try {
let entity;
// Check if the input is a URL
if (input.includes('https://t.me/')) {
const username = input.split('/').pop();
entity = await client.getEntity(username);
} else {
entity = await client.getEntity(input);
}
node.send({
payload: {input:entity},
});
} catch (err) {
node.error('Error getting entity: ' + err.message);
node.send({
payload:{ input: null}
})
}
});
}
RED.nodes.registerType('get-entity', GetEntity);
};