Skip to content

[Notifier] [Telegram] Add support for local API server #57769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.3
Choose a base branch
from

Conversation

ahmedghanem00
Copy link
Contributor

@ahmedghanem00 ahmedghanem00 commented Jul 18, 2024

Q A
Branch? 7.3
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #57766
License MIT

Since Telegram's local API server doesn't support HTTPS traffic natively, this PR introduces a new DSN option/flag to allow the disabling of bridge's default behavior of using https protocol

@OskarStark
Copy link
Contributor

I am afraid that this could lead to security issues, what about combining this flag with kernel debug parameter? Does that make sense? 🤔

@ahmedghanem00
Copy link
Contributor Author

I am afraid that this could lead to security issues

Agree, but usually this "API server" is hosted internally within the same infrastruture/server, so it might not be a big risk in that case? Maybe when it hosted on a remote server and the communication will flow over the internet, a TLS-termination server may be used in combination with it, to secure the data and keep the transmition happens on https?

We also may add an explicit caution in the readme file about this?

@ahmedghanem00
Copy link
Contributor Author

what about combining this flag with kernel debug parameter? Does that make sense? 🤔

Not sure, but usually I see options of other bridges being controlled via DSN only.

@ahmedghanem00 ahmedghanem00 force-pushed the make-protocol-schema-configurable branch from 0e0398c to ac9edca Compare August 16, 2024 08:00
@OskarStark OskarStark changed the title [Notifier] [Telegram] Add support for local API server [Notifier][Telegram] Add support for local API server Aug 16, 2024
Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After my comments

@carsonbot carsonbot changed the title [Notifier][Telegram] Add support for local API server [Notifier] [Telegram] Add support for local API server Aug 16, 2024
@OskarStark OskarStark changed the title [Notifier] [Telegram] Add support for local API server [Notifier][Telegram] Add support for local API server Aug 16, 2024
$toString = \sprintf('telegram://%s', $this->getEndpoint());
$formattedOptions = http_build_query(['channel' => $this->chatChannel, 'disable_https' => $this->disableHttps ?: null]);

if ($formattedOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something is wrong here: the condition is always true now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be true only if one of the $chatChannel or $disableHttps properties has been set to something except the default. Unless this, the condition will always be false.

echo http_build_query(['channel' => null, 'disable_https' => false ?: null]); should return an empty string which will not pass the condition.

I may use empty() function in the condition for better readability? (e.g. if (!empty($formattedOptions)))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are passing well also

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it, as I was always confused, but http_build_query behaves like array_filter and if chatChannel and disableHttps is null, $formattedOptions is not true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't get what is wrong with the http_build_query or the if statement 😅. It just tries to build a query string from a given set of class properties ($chatChannel & $disableHttps). I also have seen many other bridges use http_build_query in the same function to build the transport DSN.

If that's not a good approach, what is the alternative then?

Copy link
Contributor Author

@ahmedghanem00 ahmedghanem00 Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@ahmedghanem00 ahmedghanem00 Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola @nicolas-grekas @OskarStark, Can you have a recheck on here? Thanks

@carsonbot carsonbot changed the title [Notifier][Telegram] Add support for local API server [Notifier] [Telegram] Add support for local API server Aug 22, 2024
@fabpot fabpot removed this from the 7.2 milestone Nov 20, 2024
@fabpot fabpot added this to the 7.3 milestone Nov 20, 2024
…'s default behavior of using `https` protocol

Signed-off-by: Ahmed Ghanem <ahmedghanem7361@gmail.com>
@ahmedghanem00
Copy link
Contributor Author

@nicolas-grekas @OskarStark, Hola guys, can this PR get some review on here, whether it will be accepted or rejected😅? Thanks

@@ -14,6 +14,27 @@ where:
- `TOKEN` is your Telegram token
- `CHAT_ID` is your Telegram chat id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Example:
```
TELEGRAM_DSN=telegram://TOKEN@localhost:5001?channel=CHAT_ID&disable_https=1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In AmazonSns, this option is named sslmode. I don't know if this name is better, but I think it's better to be consistent between adapters.

$protocol = 'disable' === $dsn->getOption('sslmode') ? 'http' : 'https';

This would become:

Suggested change
TELEGRAM_DSN=telegram://TOKEN@localhost:5001?channel=CHAT_ID&disable_https=1
TELEGRAM_DSN=telegram://TOKEN@localhost:5001?channel=CHAT_ID&sslmode=disable

Copy link
Member

@GromNaN GromNaN Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you've already changed the name in response to our request #57769 (comment), but perhaps the consistency with other bridges hadn't been examined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like sslmode 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

symfony/telegram-notifier does not support local telegram api server
7 participants