[ABD] Discord Notifications -- send messages to Discord to report forum events

Any abandoned Extensions will be moved to this forum.

WARNING: Extensions in this forum are not currently being supported or maintained by the original Extension author. Proceed at your own risk.
Forum rules
IMPORTANT: Extension Development Forum rules

WARNING: Extensions in this forum are not currently being supported nor updated by the original Extension author. Proceed at your own risk.
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

[ABD] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

Release: https://github.com/rootslinux/phpbb-dis ... ations.zip
(Submitted to phpBB for official validation)


Extension Name: Discord Notfications
Author: Tyler Olsen (Roots)
Extension Description: Enables certain phpBB events to generate notification messages that get sent to a Discord channel. Some example events include: post created, topic locked, and new user account created.
Requirements: Requires the php-curl module. I'm developing against phpBB 3.2.3, but it should be compatible with 3.1.x as well.
Features:
  • Individually select which supported event types that you wish to generate notifications for
  • Select whether or not certain forums can generate events
  • For forum post events, select the maximum length of the post preview text to send in the notification
Source Code: https://github.com/rootslinux/phpbb-dis ... ifications


Hi everyone. I've been a phpBB user and administrator for around 15 years and am excited to make my first contribution to the community. I am an experienced software engineer, but am completely new to PHP. If you take a look at my source code and find any rookie mistakes or have other suggestions, I'd love to hear them.

Motive
I've had a community built around a project of mine for a number of years and our forum has always been our primary means of communication. About a year ago, I added a Discord server and our community rapidly embraced it. Unfortunately, it has left the forums in a state of semi-abandonment, and I always preferred them because of their ability to retain meaningful conversations and decisions. I found myself posting on the forums and manually copying a link over to Discord so people there would be aware of it.

Other services we use like BitBucket and MediaWiki have the ability to post discord notifications. So, I decided to install a similar extension for phpbb to automate this process. However, I found that nothing like that existed. And so here we are. While I am making this for my own uses, I think it can be a useful extension for others to use as well.

Status
I've been working on this diligently for a week now and have made great progress. All of my schema changes and configurations are in place. I have simple event handlers setup and can successfully transmit notifications to Discord. The only user-facing aspect of this extension is an ACP page, which is nearly complete, where the user can configure the type of notifications that are generated.

The major tasks I have remaining before this is ready for an alpha status are the following:
  • Test all events to make sure that notifications are properly generated for each (more difficult than I thought, as the Event List can be a little ambiguous and hard to map to my notification types)
  • Process event data and construct meaningful messages complete with links (Example: 'Roots' start a new topic in 'General Chat': 'Is this a useful phpbb extension?' -- Preview: I hope people like this ext...)
  • Add forum selections to the ACP settings page so that users can disable notification generation on certain forums (I currently no idea how to add dynamic content I'd need to add to an ACP page...)
  • Write all the unit tests
I don't want to spend too long on this project as I do have other open source projects I need to get back to working on. My hope is that I can finish this up in another week or so and then submit it to be included in the official extension DB. I'll be adding it to my own forums even before it gets officially approved though.

Feedback
I welcome any feedback or feature suggestions. For the record, here's the initial list of notification types I'm planning on rolling out with (at least, these are the ones I'm interested in myself as a user).
  • Topic: create, update, delete, lock, unlock
  • Post: create, update, delete, lock, unlock
  • User: create, delete
Last edited by Roots on Sat Nov 10, 2018 1:55 am, edited 2 times in total.
dapico
Registered User
Posts: 7
Joined: Tue Oct 16, 2018 1:09 am

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by dapico »

What about adding PM notifications?
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

dapico wrote: Mon Oct 22, 2018 6:45 pm What about adding PM notifications?
I didn't think that would be a desirable feature for most people. PMs are, by definition, private conversations between two individuals. The only use case I can imagine for this are if you are a phpBB admin and for some reason, want to monitor all private communications between your users (creepy). If instead you meant that you get a notification on Discord when only your forum account receives a PM, that makes a little more sense, but it is also much more complicated feature to build out as it would require adding a setting to the UCP that users would have to self-manage to tie their two accounts together.

My intent with this system is that the notifications be sent to a public Discord channel that any user (or even guest) can see. Of course you can also make the channel that the notifications get sent to be a private one that only admins have access to, and they can then use it to easily monitor forum activity without needing to actually visit the forum in their browser.


One future thought I had in mind was possibly supporting multiple webhooks instead of just one. You could then configure different notifications to be published on different webhooks. I don't think that this would be very useful to most, however, and in the name of keeping things simple I'm planning to only support a single webhook for the first release.
User avatar
lozu
Registered User
Posts: 59
Joined: Tue Nov 10, 2009 11:07 am

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by lozu »

I was thinking using bell (not the actual PM system) to notified of new discord? Also can we set up the interval before each messages get dumped?
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

lozu wrote: Thu Oct 25, 2018 12:36 am I was thinking using bell (not the actual PM system) to notified of new discord? Also can we set up the interval before each messages get dumped?
I'm not sure what you mean by the bell...do you mean just the standard Discord sounds when someone posts in a channel? This notification system does not send anyone PMs in Discord. It uses a webhook, which is essentially a bot that you attach to a channel and the bot sends a message to the channel when it receives input from the webhook. The webhook can attach to any channel, public or private.

There is no interval before messages get sent. The notifications are immediate. If someone writes a new post on the forum you'll receive the notification just after they click that "submit" button. I don't have any intention of changing this design for the initial relese, but I could see an argument being made for a future feature that allows the user to configure the system to "send notifications in batch every X minutes".



Just a few minutes ago I got the first rich-content notification published from my test forum. I'm too lazy to post a screenshot, but here's what it generally looks like in Discord. This notification was generated when I posted a new reply to an existing topic.
Forum Activity (BOT)
:page_facing_up: Roots created a new post in the topic New Sexy For Testing located in the forum User Feedback
All of those links direct you to exactly where you think they would take you: user profile page, post, topic, and forum URLs. It works great! :D
User avatar
lozu
Registered User
Posts: 59
Joined: Tue Nov 10, 2009 11:07 am

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by lozu »

Roots wrote: Thu Oct 25, 2018 2:40 am
lozu wrote: Thu Oct 25, 2018 12:36 am I was thinking using bell (not the actual PM system) to notified of new discord? Also can we set up the interval before each messages get dumped?
I'm not sure what you mean by the bell...do you mean just the standard Discord sounds when someone posts in a channel? This notification system does not send anyone PMs in Discord. It uses a webhook, which is essentially a bot that you attach to a channel and the bot sends a message to the channel when it receives input from the webhook. The webhook can attach to any channel, public or private.

There is no interval before messages get sent. The notifications are immediate. If someone writes a new post on the forum you'll receive the notification just after they click that "submit" button. I don't have any intention of changing this design for the initial relese, but I could see an argument being made for a future feature that allows the user to configure the system to "send notifications in batch every X minutes".



Just a few minutes ago I got the first rich-content notification published from my test forum. I'm too lazy to post a screenshot, but here's what it generally looks like in Discord. This notification was generated when I posted a new reply to an existing topic.
Forum Activity (BOT)
:page_facing_up: Roots created a new post in the topic New Sexy For Testing located in the forum User Feedback
All of those links direct you to exactly where you think they would take you: user profile page, post, topic, and forum URLs. It works great! :D
Okay. Never mind...
Would be great if x amount was implemented consider how some Discord goes crazy sometimes.
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

I am getting very close to having an initial release for this extension now. The only major task I have remaining is to processing a few more events and turn them into structured notifications (I have about half of them done now).

I am running into a few issues with some things. If anyone can give me pointers on the following problems, that would be a great help.
  • Determining if there's an easy way to remove phpbb formatting tags from post text to make the previews easier to read
  • Debugging why sending newline characters from php-curl breaks notifications (using newline characters with curl on the command line works no problem)
  • Seeing if there's a fast and easy way to get a user/forum/topic/post name when all I have are IDs (some events I listen on only return IDs and I'd really like to have the names without having to run a query for it every time)
Once I've finished this work and thoroughly tested it, I'll be taking the next steps to formally package and submit it. I'm going to install it live into my production forums as well. When that's ready, I'll post an update with screenshots and a link to my forums + Discord so people can take a look if they're interested.
Febreen
Registered User
Posts: 20
Joined: Tue Apr 18, 2017 5:44 pm

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by Febreen »

Hi Guys,

Thank you for this extension..It's great and she works fine for me.
I change the folder "En" in "Fr" and translate in french for me (I can send u the folder to add in your extension if u want).

Just a problem: On discord, the annoucements stay in english:

Image

How can i translate this?


And i have an idea to update this extension:

It's will be geat if we can add more Webhooks. For example, i add a webhook for the channel "Forum-Annoucements" and the topics of all annoucements go in this channel on discord.
And i add a second webhook fore the channel "Forum-Problems" and the topics of all problems of the members go in this channel on discord.
I don't know if it's possible.

Thank you so much, and sorry for my bad english i learn it a bit at school and nothing later. ^^
aedgington
Registered User
Posts: 5
Joined: Sat Dec 11, 2010 3:28 pm

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by aedgington »

Roots wrote: Sat Oct 27, 2018 8:51 am [*]Determining if there's an easy way to remove phpbb formatting tags from post text to make the previews easier to read
notification_event_listener.php

Code: Select all

			$footer = $data['content'];
			
			function stripBBCode($text_to_search) {
			 $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
			 $replace = '';
			 return preg_replace($pattern, $replace, $text_to_search);
			}

			$footer = strip_tags($footer);
			$footer = stripBBCode($footer);
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

Febreen wrote: How can i translate this?
First of all, awesome! I'm glad that people are making use of this already even before it's finished.

One of the next tasks on my list is to move the current notification messages into a language file (right now they are hard-coded into the PHP code for convenience). I just started doing this last night. I'll post here again when it's ready for a translation, and then it should be simple for you to add a translation.

By the way, if you like feel free to submit a pull request with your translation files and we can add it to the initial release. :D
Febreen wrote: And i have an idea to update this extension:

It's will be geat if we can add more Webhooks. For example, i add a webhook for the channel "Forum-Annoucements" and the topics of all annoucements go in this channel on discord.
And i add a second webhook fore the channel "Forum-Problems" and the topics of all problems of the members go in this channel on discord.
I don't know if it's possible.
I had this idea as well. It is certainly possible to do this, but it will make the extension much more complicated. I opted not to support multiple webhooks in the initial release. If enough people request this feature in the future, I would be willing to support that in a future release.

aedgington wrote: Wed Oct 31, 2018 1:44 pm
Roots wrote: Sat Oct 27, 2018 8:51 am [*]Determining if there's an easy way to remove phpbb formatting tags from post text to make the previews easier to read
notification_event_listener.php

Code: Select all

			$footer = $data['content'];
			
			function stripBBCode($text_to_search) {
			 $pattern = '|[[\/\!]*?[^\[\]]*?]|si';
			 $replace = '';
			 return preg_replace($pattern, $replace, $text_to_search);
			}

			$footer = strip_tags($footer);
			$footer = stripBBCode($footer);
Thanks for the help!
aedgington
Registered User
Posts: 5
Joined: Sat Dec 11, 2010 3:28 pm

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by aedgington »

Roots wrote: Wed Oct 31, 2018 11:16 pmThanks for the help!
No problem -- wonderful mod.

If you're taking suggestions?

https://birdie0.github.io/discord-webho ... rname.html
https://birdie0.github.io/discord-webho ... r_url.html

It looks like the webhooks support overriding the bot's username and avatar inside Discord. I'd love to see an option to substitute the forum username and avatar for the bot's. It shouldn't be that difficult to pass it through (already getting the username, add user_avatar into the query) in execute_discord_webhook's $post. But as you've said your time is limited and many thanks already for what you've done!
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

Re: [DEV] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

https://github.com/rootslinux/phpbb-dis ... ssages.php

I moved the notification message text to a new language file tonight, so you should be able to translate that now. A couple notes:
  • Three of the notification strings are blank currently, because I haven't yet implemented handlers for those events. They'll be filled out eventually.
  • I may make significant changes to the original messages. For example I think I'm going to rename all the things named "update" to "edit" because that word is just a better description of the type of event that occurs.
aedgington wrote: Wed Oct 31, 2018 11:31 pm If you're taking suggestions?

https://birdie0.github.io/discord-webho ... rname.html
https://birdie0.github.io/discord-webho ... r_url.html

It looks like the webhooks support overriding the bot's username and avatar inside Discord. I'd love to see an option to substitute the forum username and avatar for the bot's. It shouldn't be that difficult to pass it through (already getting the username, add user_avatar into the query) in execute_discord_webhook's $post. But as you've said your time is limited and many thanks already for what you've done!
Wow, I like that suggestion a lot actually. The only concern I have is that forum names can be up to 255 characters and I can't find what the size limit for bot username overrides are. Also I like that page you linked a lot better than the official discord documentation that I've been using: https://discordapp.com/developers/docs/ ... te-webhook -- the example images help a lot!

In addition to that suggestion for overriding the bot with the forum info, I'd like to set the author information with the relevant user's forum name/profile link/avatar. https://birdie0.github.io/discord-webho ... uthor.html


You're right that this shouldn't be too difficult to do, but I think I'll leave it as a feature to add after the initial release. I'd really like to wrap this up and get it out the door soon (or at least officially submit it so I can address any feedback that the extensions team has). Feel free to add an issue to the github page as a feature request so we can track it. I'll do it myself in a couple days if it isn't added already.
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

Re: [3.2][ALPHA] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

https://github.com/rootslinux/phpbb-dis ... ifications

As of pull request #18, this extension is now functionally complete. If you want to give it a try, go right ahead. I'd exercise caution about using it in a live production board as it still needs some testing, but I'm reasonably confident that no major errors will occur.


There's still a little work to be done before I officially submit it.
  • Try to fix a bug that prevents messages from being sent if they contain newline characters (right now those are simply replaced with spaces)
  • Add some additional information on the ACP page to point users to instructions on how to setup their Discord webhooks
  • Write unit tests, or remove the ones that were created by default when I built the extension skeleton
  • Review all the code to make sure there's no incorrect comments, dead code, or debug code left
  • Run the extension through the validation tool and correct any errors
Once I'm done with that and submit it, I'll build a beta release package and publish it while we wait for the extension to be officially included (I have no idea how long that will take).
User avatar
EFiNSTORM
Registered User
Posts: 164
Joined: Fri Dec 26, 2008 4:09 am
Location: localhost

Re: [3.2][ALPHA] Discord Notifications -- send messages to Discord to report forum events

Post by EFiNSTORM »

Hi,

Found a minor bug when a user registers it does send the username to discord.

Image

Thanks.
Roots
Registered User
Posts: 47
Joined: Thu Jun 17, 2004 12:53 pm
Location: Austin TX
Contact:

Re: [3.2][ALPHA] Discord Notifications -- send messages to Discord to report forum events

Post by Roots »

Thanks. I think I found the problem. I'll be pushing the fix shortly.
Locked

Return to “Abandoned Extensions”