Page 1 of 4

[ABD] Telegram Notifications

Posted: Thu Jul 27, 2017 11:34 am
by lassik
Extension Name: Telegram Notifications
Author: lassik

Extension Description: Notify on Telegram whenever someone posts on phpBB
Extension Version: 0.6.0 (BETA)

Features: Adds a panel to the ACP where you can type in the Auth Token of your Telegram bot and the Chat ID of the Telegram chat where to send notifications. The extension will then send a short notification message to the Telegram chatroom whenever someone makes a post on your phpBB forum. The notifications look like this:
Telegram Bot wrote: [lassik] Quote: Title of the topic
Extension Download: https://github.com/lassik/phpbb-ext-tel ... _0_6_0.zip

Extension GitHub Page:: https://github.com/lassik/phpbb-ext-tel ... ifications

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 12:00 pm
by lassik
This extension works and it's in daily use on a small forum of ours. It also passes almost all of the EPV (extension prevalidator) checks. But polish is lacking:
  • The ACP language translations (L_WHATEVER) do not work. I couldn't figure out why.
  • I'm using PHP's curl API to access Telegram via HTTPS. Is it OK to rely on curl?
  • This is my first PHP and phpBB project, so I'm afraid the coding style is far from exemplary.
  • There isn't yet a ready-to-download zip file, one must clone the Git repo to install it.
If someone would like to help get this polished to the point where it's acceptable to submit to the extension database, I'd be very happy. Until then, it's perfectly usable as-is, just a little more difficult to set up. Also, if someone other than me wants to be the long-term maintainer, that's even better :D I just wanted to get the job done because our club needed this.

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 12:20 pm
by kasimi
The add_lang() method is from 3.1 and doesn't work with extensions:
https://github.com/lassik/phpbb-ext-tel ... le.php#L20

Try using 3.2's language service instead: https://area51.phpbb.com/docs/dev/32x/e ... age-object

Code: Select all

global $phpbb_container;
$lang = $phpbb_container->get('language');
$lang->add_lang('common', 'lassik/telegramnotifications');
lassik wrote:
Thu Jul 27, 2017 12:00 pm
Is it OK to rely on curl?
Yes it is, as long as it doesn't break the board if cURL isn't available. :)

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 12:24 pm
by david63
lassik wrote:
Thu Jul 27, 2017 12:00 pm
There isn't yet a ready-to-download zip file, one must clone the Git repo to install it.
Creating a "Release" on Github will automatically create a .zip for you.

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 1:42 pm
by lassik
Thanks for the extremely quick feedback! I made the suggested changes and pushed to GitHub.
kasimi wrote:
Thu Jul 27, 2017 12:20 pm
Try using 3.2's language service instead: https://area51.phpbb.com/docs/dev/32x/e ... age-object
Got this to work. Except for one part: The ACP's EXTENSIONS tab still shows "ACP_TELEGRAM_NOTIFICATIONS" instead of "Telegram Notifications" (what ACP_TELEGRAM_NOTIFICATIONS expands to) as the category title in the left sidebar.
kasimi wrote:
Thu Jul 27, 2017 12:20 pm
lassik wrote:
Thu Jul 27, 2017 12:00 pm
Is it OK to rely on curl?
Yes it is, as long as it doesn't break the board if cURL isn't available. :)
I added a check for function_exists('curl_version')
david63 wrote:
Thu Jul 27, 2017 12:24 pm
Creating a "Release" on Github will automatically create a .zip for you.
I'm ready to make a release. But will the directory structure be appropriate if the "acp", "adm", "config" etc. directories are at the top level of the zip file (as GitHub will make it) - or should all of that stuff be in a subdirectory inside the zip file? If so, what's the customary way to solve this problem if I want to keep the Git repo's directory structure as-is?

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 2:07 pm
by david63
lassik wrote:
Thu Jul 27, 2017 1:42 pm
But will the directory structure be appropriate
Creating a release will sort out the correct directory structure - just try it and see - you can always delete it if it not what you want.
lassik wrote:
Thu Jul 27, 2017 1:42 pm
The ACP's EXTENSIONS tab still shows "ACP_TELEGRAM_NOTIFICATIONS" instead of "Telegram Notifications"
You need to have those language variables in an info_acp_namespace.php file

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 2:36 pm
by lassik

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 3:26 pm
by lassik
Should I just submit that zipfile to the customization database and fix any EPV issues, or do you want to pre-check it from GitHub first?

Re: [3.2][ALPHA] Telegram Notifications

Posted: Thu Jul 27, 2017 5:57 pm
by david63
I would suggest that before you even consider submitting it to the CDB that you review the phpBB coding guidelines as there are several parts of your code that do not comply.

Re: [3.2][ALPHA] Telegram Notifications

Posted: Tue Aug 01, 2017 2:46 pm
by lassik
I read the entire coding guidelines document and made the following fixes:
  • Use tabs for indentation.
  • Do not forget to comment the functions.
  • Do not forget to comment the class.
  • Classes need a separate @package definition.
  • Always include the braces.
  • Where to put the braces.
  • Commas after every array element.
Commit log on GitHub: https://github.com/lassik/phpbb-ext-tel ... its/master

Re: [3.2][BETA] Telegram Notifications

Posted: Wed Aug 02, 2017 7:30 am
by lassik
Just posted the first zip file ready for testing (EDIT: well, the second one after the previous attempt to generate one automatically from GitHub - this one has proper subdirectories): https://github.com/lassik/phpbb-ext-tel ... s_HEAD.zip

One thing - I now send HTML-formatted Telegram messages so I can have the topic titles be clickable links instead of showing the long post URL directly in the message. This causes EPV to complain about the use of the htmlspecialchars() function (which I use to escape the HTML before sending it to the Telegram API). What function should I use instead to do the escaping? The relevant lines of source code are: https://github.com/lassik/phpbb-ext-tel ... hp#L58-L62

Re: [3.2][BETA] Telegram Notifications

Posted: Wed Aug 02, 2017 3:34 pm
by romeo_piter
Will this ext work in 3.1?

Re: [3.2][BETA] Telegram Notifications

Posted: Thu Aug 03, 2017 8:14 am
by potku
This seems interesting! :)

Since I know nothing about Telegram bots, where can that chat ID be found? Or how is that chat created, I guess... :D I did create a bot and received that token.

Re: [3.2][BETA] Telegram Notifications

Posted: Thu Aug 03, 2017 9:53 am
by lassik
Thanks for your interest :)
romeo_piter wrote:
Wed Aug 02, 2017 3:34 pm
Will this ext work in 3.1?
Nope, sorry. 3.2 only.
potku wrote:
Thu Aug 03, 2017 8:14 am
where can that chat ID be found? Or how is that chat created, I guess... :D
You invite your bot to an existing group chat (the one where you want the bot to send notifications about new posts). Then input the chat ID of that group chat into the phpBB ACP. Unfortunately the chat ID is a bit tricky to find. Can you manage with these instructions? https://stackoverflow.com/a/32572159

Re: [3.2][BETA] Telegram Notifications

Posted: Thu Aug 03, 2017 10:50 am
by potku
Thanks for the link. I did have a look at couple of those before, but I really have always found Stackoverflow's UI very...different, to be polite. :D It's a shame I cannot stand it because there is a lot of information there.

However, I did some digging around. I should be at a point where that ID is the only thing missing. Is it the one with a negative sign in front of it (I read that for groups it's like that)?

Code: Select all

{"ok":true,"result":[{"update_id":xxxxxxx,
"message":{"message_id":4,"from":{"id":xxxxxx,"first_name":"xxxxx","language_code":"fi-FI"},"chat":{"id":-xxxxxx,"title":"Potku.net","type":"group","all_members_are_administrators":true},"date":1501756766,"text":"/register","entities":[{"type":"bot_command","offset":0,"length":9}]}}]}
EDIT: I think it must be. In that case, the bot is not delivering messages to the group. But since this EXT does work, we must have done something wrong...