Warning This repository is archived for read-only purpose and is not maintained anymore. If you're a PHP developer and interested in maintaining this repository, create a new discussion and let us know, please.
Telegram Web Bridge is a bidirectional, web-based, proxy-like application which can act as a middleman for Telegram Bot API requests (from your actual application to Telegram) and Webhooks (from Telegram to your actual application).
Built on Slim framework, light-weight and works smoothly.
This bridge can be useful in situations in which accessing Telegram Bot API is not possible (like being hosted in a country restricting/blocking access to Telegram).
Here are the problems come in:
- We can't host our main application outside that region
- We can't call Telegram Bot API
- We can't receive their webhooks
- ... but we still need Telegram!
Here this bridge comes in. You can host it in outside of the blocking region, use it to call APIs and receive webhooks.
Yes, there are plenty of other solutions too. However, not everyone can implement those solutions without technical knowledge.
This is a deployment-ready application built to be hosted even on a shared-hosting (since they are pretty cheap) without hassles. Simply download, extract on your shared web hosting, change few settings and done!
The bridge application requires following conditions:
- A shared-hosting, VPS or dedicated server
- PHP version 7 or above with
json
extension enabled. - An installed SSL certificate. Can be Self-Signed but LetsEncrypts free certificates are much easier to setup! If you have a paid certificate, its good too.
You can either use deployment-ready archive or clone source code and build for yourself.
Visit following link and download the latest version:
Download Builds
Unzip the content of the build into a publicly accessible directory on your shared hosting. URL to that directory will be your appUrl
in settings.
⛓ Jump to next section to continue installation.
Clone this repository on your server or local computer:
$ git clone https://github.com/AmirrezaNasiri/telegram-web-bridge
Use Composer to install dependencies:
$ composer install
Basic tests for API calls are available but for webhooks, no tests has been written yet.
Create a Telegram bot for testing purpose and start chatting with it. Open tests/settings.php
and configurate like this:
Enter the API token created for test bot:
'botApiToken' => '123456789:aBcdEfghIjklm_nOpqRsTuvWXyZaBcDEFjhi',
Specify your chat id (can be extracted from @chatid_echo_bot):
'chatId' => '123456789,
Then run tests:
$ composer test
All configurable settings are located and described in:
src/settings.php
Basically, you only need to change appUrl
, crtPath
and webhookEndpoints
settings.
Now that everything is ready, you just need to change the request URLs from https://api.telegram.org
to what you've set in appUrl
.
For example, following request
GET https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe
Must be changed to:
GET https://example.com/path-to/telegram-web-hook/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe
To receive webhook callbacks, you need to fire setWebhook
once again:
POST https://example.com/path-to/telegram-web-hook/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/setWebhook
The bridge will inject its own url
and certificate
parameters according to settings you've just set. So you should expect result of getWebhookInfo
to be different than what you've sent in setWebhook
request.
On every callback from Telegram, bridge will catch and forward it to the defined URL in the settings file.
No problem. You may be able to easily change target of requests from Telegram's URL to your bridge. Here are tips for several packages:
- irazasyed/telegram-bot-sdk:
If you're using this package in a Laravel projects, see how to change BASE_BOT_URL to your bridge.
This project welcomes community contributions.
- Submit security-related bugs to me:
hi``@``amirreza.in
. - Submit any other kind of bugs and issues and help us fix them.
- Submit pull requests for bug fixes and features and discuss existing proposals.
Code is licensed under the MIT License.
- Telegram Bot API
- ByteGate (our blog)
- تبدیل PDF به ورد (our sponsored service)