A scalable and advanced WordPress boilerplate plugin for connecting a Telegram bot to your website.
v3.3.0 (Changelog)
Libraries used: PHP Telegram Bot
- PHP: 8.0 or higher
- WordPress: 5.0 or higher
- Composer: For dependency management
Clone or download this repository, and then you'll need to do a four-step CASE-SENSITIVE find and replace in all the codes:
- Search for
TelegramPluginBoilerplateto capture the namespaces. - Search for
FDTBWPBto capture the constants. - Search for
fdtbwpbto capture option name and slugs. - Search for
telegram-plugin-boilerplateto capture the text domains.
Then, update the header in plugin.php with your own information.
AFTER you have done the find and replace, run this command in the plugin root:
$ composer installCreate a bot with @BotFather and copy the token.
- Enable the plugin
- Copy bot's token and username (with
@) in the plugin's settings - Open the
options-permalink.phppage so that the API endpoints get refreshed
To test the bot on a local environment, add this constant to your wp-config.php file:
define('WP_ENVIRONMENT_TYPE', 'local');
And use this endpoint to handle the updates (e.g. each time you message the bot):
https://{WEBSITE.COM}/wp-json/fdtbwpb/v1/get-message-polling
To enable your bot for a production website, set the bot's webhook to the get-message endpoint:
https://api.telegram.org/bot{TOKEN}/setWebhook?url=https://{WEBSITE.COM}/wp-json/fdtbwpb/v1/get-message
If your server can't access Telegram, you can use a middleman server to redirect requests:
- Change
CURLOPT_URL's value in forward.php - Upload forward.php and forward-to-telegram.php to your middleman server
- Use
forward's URL as bot's webhook - Copy the
forward-to-telegram's full link in the plugin's settings
You can see bot's error log file here:
wp-content/plugins/telegram-plugin-boilerplate/logs/
You can find more examples and sample codes/methods/classes in the base WordPress Plugin Boilerplate repository.
- Open terminal in the plugin root, and run this command to generate the POT file with WP-CLI:
$ wp i18n make-pot . languages/telegram-plugin-boilerplate.pot-
Create translations with PoEdit:
- Open PoEdit and choose "Create new translation" or "New from POT file".
- Select
languages/telegram-plugin-boilerplate.pot. - Choose your target language locale, for example
de_DEfor German. - Translate each string.
- Save the file as
languages/telegram-plugin-boilerplate-de_DE.po. - PoEdit will automatically generate
languages/telegram-plugin-boilerplate-de_DE.mo.
-
Keep translations up to date:
- After adding or changing strings, regenerate the POT file.
- Reopen the updated POT in PoEdit and choose "Update from POT file" to update your translations.
This project is licensed under the MIT License - see the LICENSE file for details.