Skip to content

Commit 31c8e17

Browse files
author
windka
committed
added further filters
added client api
1 parent 44a5ef6 commit 31c8e17

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
33

44
# [0.1.4] - 2023-10-15
55
### added further filters - [#3](https://github.com/windkh/node-red-node-telegrambot/issues/3)
6+
### added client api - [#5](https://github.com/windkh/node-red-node-telegrambot/issues/5)
67

78
# [0.1.3] - 2023-10-12
89
### added proxy support - [#2](https://github.com/windkh/node-red-node-telegrambot/issues/2)

examples/Client.sendMessage.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"id":"7f66f74d4da2179d","type":"telegram client sender","z":"3d8bc5187eb93fc0","name":"","bot":"b4217d5b3ad6f705","x":660,"y":520,"wires":[["fce968085d0d85fb"]]},{"id":"fce968085d0d85fb","type":"debug","z":"3d8bc5187eb93fc0","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":520,"wires":[]},{"id":"2ebb4c5feea34fc6","type":"function","z":"3d8bc5187eb93fc0","name":"send message","func":"msg.payload = {\n // api: '', undefined or empty means that the client is api is called\n func: 'sendMessage',\n args: [\n 'me',\n { message: \"Hello **world!**\" }\n ]\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":520,"wires":[["7f66f74d4da2179d"]]},{"id":"0cc00f7ebb66ea44","type":"inject","z":"3d8bc5187eb93fc0","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":520,"wires":[["2ebb4c5feea34fc6"]]},{"id":"b4217d5b3ad6f705","type":"telegram client config","botname":"Martina","verboselogging":true,"loginmode":"user","useproxy":true,"usewss":false,"host":"192.168.178.71","sockstype":"5","port":"1080","username":"","password":"","secret":"d0d6e111bada5511fcce9584deadbeef","mtproxy":false,"timeout":"2"}]

telegrambot/telegrambot.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,20 @@ module.exports = function (RED) {
526526
let func = msg.payload.func;
527527
let args = msg.payload.args || {};
528528

529-
if (api !== undefined && func !== undefined) {
529+
if (func !== undefined) {
530530
(async () => {
531531
try {
532-
let request = new Api[api][func](args);
533-
const result = await client.invoke(request);
532+
let result;
533+
if (api === undefined || api === '') {
534+
// sendMessage, forwardMessages, editMessage, deleteMessages, pinMessage, unpinMessage, markAsRead, sendFile
535+
// args must be an array
536+
result = client[func](...args);
537+
} else {
538+
// args must be an object
539+
let request = new Api[api][func](args);
540+
result = await client.invoke(request);
541+
}
542+
534543
msg.payload = result;
535544
nodeSend(msg);
536545
} catch (error) {

0 commit comments

Comments
 (0)