Skip to content

Commit

Permalink
fixed #315
Browse files Browse the repository at this point in the history
  • Loading branch information
windka committed Jun 20, 2023
1 parent 728306c commit 271d4c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

# [15.1.4] - 2023-06-20
### control node can execute commands - [#315](https://github.com/windkh/node-red-contrib-telegrambot/issues/315)

# [15.1.3] - 2023-06-13
### added chat_id in options - [#306](https://github.com/windkh/node-red-contrib-telegrambot/issues/306)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-telegrambot",
"version": "15.1.3",
"version": "15.1.4",
"description": "Telegram bot nodes for Node-RED",
"dependencies": {
"bluebird": "^3.7.2",
Expand Down
37 changes: 34 additions & 3 deletions telegrambot/99-telegrambot.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,15 @@ module.exports = function (RED) {
return found;
};

this.sendToAllCommandNodes = function (botMsg, done) {
for (let nodeId in self.commandsByNode) {
let node = RED.nodes.getNode(nodeId);
node.processMessage(botMsg);
}

done();
};

this.getBotCommands = function () {
return self.commandsByLanguage;
};
Expand Down Expand Up @@ -3180,17 +3189,19 @@ module.exports = function (RED) {
if (msg.payload) {
let command = msg.payload.command;
switch (command) {
case 'stop':
case 'stop': {
node.config.stop('by control node', function () {
node.send(msg);
});
break;
case 'start':
}
case 'start': {
node.config.start('by control node', function () {
node.send(msg);
});
break;
case 'restart':
}
case 'restart': {
node.config.stop('by control node', function () {
let delay = msg.payload.delay;
if (delay !== undefined && delay > 0) {
Expand All @@ -3207,7 +3218,27 @@ module.exports = function (RED) {
node.send(msg);
});
break;
}
case 'command': {
let message = msg.payload.message;
if (message.from === undefined) {
message.from = {
id: 0,
username: 'unknown',
};
}

if (message.chat === undefined) {
message.chat = {
id: 0,
};
}

node.config.sendToAllCommandNodes(message, function () {
node.send(msg);
});
break;
}
default:
break;
}
Expand Down

0 comments on commit 271d4c3

Please sign in to comment.