The discussion revolves around the ‘discourse-chat-integration’ plugin, specifically around checking if a notification is for a post or a thread. jackkelly-bayliss is trying to create separate notification blocks for each and is having trouble identifying the correct method.
david suggests using post_number to determine if it’s a post or thread, and later clarifies that the first post in a topic has post_number==1, not post_number==0. jackkelly-bayliss provides a screenshot of the code, and david suggests changing the message lines to return message to stop execution of the function.
After some troubleshooting, jackkelly-bayliss successfully implements the changes, but later asks about retrieving a user’s custom field value. david suggests using post.user.custom_fields["custom_field_name"], but jackkelly-bayliss is having trouble retrieving the value of the custom field ‘Embed Colour’.
The discussion also touches on the possibility of using existing configuration options instead of maintaining a fork of the plugin, as mentioned by david and david provides a link to the configuration rules in the ‘chatroom-integration-plugin-discourse-chat-integration’ topic.
I’m currently attempting to build upon an already existing plugin called ‘discourse-chat-integration’ for which I’ve forked and attempted to customize for a certain community but I’m having a wee mind blank. How would I specifically test if it’s a post or thread? I’m trying to build two seperate notification blocks, one for a post and another for a thread.
I have attempted to find it already with ‘post_number’ but it doesn’t seem to work. Any ideas? Thank you.
Thank you for your reply and response my topic. Would this be the correct method in completing the task? The first block should only send if it’s a thread and the second block should only send if it’s a post.
Yes, that looks roughly correct. I think you will need to change the two
message
lines to
return message
so that it stops execution of the function at that point.
What are you trying to achieve here? It might be possible to do something using the existing configuration options, rather than maintaining a fork of the plugin.
Thank you for your reply, I will change the stated lines and test now. Currently the plugin will send a Webhook to Discord on any new topics or posts. I am quite new to Ruby so I apologize for the lack of knowledge with this situation.
You can control whether you want “topic” and/or “post” notifications in the admin user interface. More information is in the “configuring rules” section here: Discourse Chat Integrations
I came across that option previously but I want a totally seperate notification layout for each. I’ve changes the lines you stated previously but it’s throwing an error at me now which suggests that no message is being returned from the previous screenshot.
Thank you for responding. I did link the file I am referring to in my thread description. These are the errors I am receiving, I would assume that I need to include some kind of file. Any thoughts?
I apologise for bumping this thread but integrating with this code, how would I be able to retrieve a user’s custom field value? Would this even be possible at all?
Yes, if that’s possible. I’ve created a custom field named ‘Embed Colour’ and added it into the code but it appears to be blank when it’s retrieved. Any suggestions?