Skip to content

Commit

Permalink
tried to fix #343
Browse files Browse the repository at this point in the history
  • Loading branch information
windka committed Sep 15, 2024
1 parent bb892ad commit 34dfcb7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 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.

# [16.1.0] - 2024-09-15
### IP address family can be configured now - [#343](https://github.com/windkh/node-red-contrib-telegrambot/issues/343)

# [16.0.2] - 2024-07-02
### tried to fix unhandled exception in sender node - [#377](https://github.com/windkh/node-red-contrib-telegrambot/issues/377)

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ The *None* method may be chosen to avoid traffic due to polling or incoming webh
You can only send messages using the sender node but you can not receive any data.


### Configuration property *IP address family*
You can force a certain IP version to be used when making requests to the telegram server.
Normally this is up to the operating system und you can just keep the default setting "Any".
If you discover problems e.g. the telegram server is unreachable. Then you can try to force
using IPv4 or IPv6.


### Configuration property flag *Use SOCKS*
SOCKS4/5 proxy support is optional when running behind a SOCKS4/5 proxy that requires authentication. In this case, additional configuration properties have to be set in the configuration node.

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": "16.0.2",
"version": "16.1.0",
"description": "Telegram bot nodes for Node-RED",
"dependencies": {
"bluebird": "^3.7.2",
Expand Down
19 changes: 18 additions & 1 deletion telegrambot/99-telegrambot.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
testenvironment: { value: false, required: false },

updatemode: { value: "polling", required: true },
addressfamily : { value: "", required: false },

// only for polling mode
pollinterval: { value: 300, required: false, validate:function(v) { return ((v === "") || (RED.validators.number(v) && (v >= 0) && (v <= 2147483))) }},
Expand Down Expand Up @@ -62,7 +63,14 @@
}
};
updateOptions();
$("#node-config-input-updatemode").change(updateOptions);
$("#node-config-input-addressfamily").change(updateOptions);

// IP address family
var updateAddressFamily = function() {
var mode = $("#node-config-input-addressfamily").val();
};
updateAddressFamily();
$("#node-config-input-addressfamily").change(updateAddressFamily);

// sslTerminated on / off
var sslTerminated = function() {
Expand Down Expand Up @@ -135,6 +143,15 @@
</select>
</div>

<div class="form-row">
<label for="node-config-input-addressfamily"><i class="fa fa-link"></i> IP Address Family</label>
<select id="node-config-input-addressfamily">
<option value="4">IPv4</option>
<option value="6">IPv6</option>
<option value="">Any</option>
</select>
</div>

<hr align="middle"/>

<div class="form-row hidden" id="polling" style="background: var(--red-ui-tertiary-background)">
Expand Down
27 changes: 23 additions & 4 deletions telegrambot/99-telegrambot.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ module.exports = function (RED) {
this.updateMode = 'polling';
}

this.addressFamily = parseInt(n.addressfamily);

// 1. optional when polling mode is used
this.pollInterval = parseInt(n.pollinterval);
if (isNaN(this.pollInterval)) {
Expand Down Expand Up @@ -235,12 +237,29 @@ module.exports = function (RED) {
agentOptions.password = n.sockspassword;
}

this.socksRequest = {
if (!isNaN(this.addressFamily)) {
agentOptions.family = this.addressFamily;
}

this.request = {
agentClass: SocksProxyAgent,
agentOptions: agentOptions,
pool: {},
};
}

Check failure on line 249 in telegrambot/99-telegrambot.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Delete `␍⏎·······`

Check failure on line 249 in telegrambot/99-telegrambot.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Delete `␍⏎·······`

Check failure on line 249 in telegrambot/99-telegrambot.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Delete `␍⏎·······`
else {
let agentOptions = {
keepAlive: true

Check failure on line 252 in telegrambot/99-telegrambot.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Insert `,`

Check failure on line 252 in telegrambot/99-telegrambot.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Insert `,`

Check failure on line 252 in telegrambot/99-telegrambot.js

View workflow job for this annotation

GitHub Actions / build (20.x)

Insert `,`
};

if (!isNaN(this.addressFamily)) {
agentOptions.family = this.addressFamily;
}

this.request = {
agentOptions: agentOptions,
};
}

this.useWebhook = false;
if (this.updateMode == 'webhook') {
Expand Down Expand Up @@ -271,7 +290,7 @@ module.exports = function (RED) {
webHook: webHook,
baseApiUrl: this.baseApiUrl,
testEnvironment: this.testEnvironment,
request: this.socksRequest,
request: this.request,
};

newTelegramBot = new telegramBotEx(this.token, options);
Expand Down Expand Up @@ -378,7 +397,7 @@ module.exports = function (RED) {
polling: polling,
baseApiUrl: this.baseApiUrl,
testEnvironment: this.testEnvironment,
request: this.socksRequest,
request: this.request,
};
newTelegramBot = new telegramBotEx(this.token, options);

Expand Down Expand Up @@ -433,7 +452,7 @@ module.exports = function (RED) {
const options = {
baseApiUrl: this.baseApiUrl,
testEnvironment: this.testEnvironment,
request: this.socksRequest,
request: this.request,
};
newTelegramBot = new telegramBotEx(this.token, options);

Expand Down

0 comments on commit 34dfcb7

Please sign in to comment.