bytechefhq / bytechef

Open-source, low-code, extendable API integration & workflow automation platform. Integrate your organizations or your SaaS product with any third party API
https://www.bytechef.io
Other
220 stars 51 forks source link

Discord - New Message trigger #1547

Open monikakuster opened 1 month ago

monikakuster commented 1 month ago

The New Message trigger for Discord component is activated whenever a new message is sent in a specific Discord channel. It enables real-time automation of workflows by responding to incoming messages as soon they apear in the designated channel. This is especially useful for monitoring communication, extracting data, or initiating processes based on the content of the messages.

Trigger Properties:

Output:

Documentation Reference: https://discord.com/developers/docs/resources/webhook#create-webhook

sikehish commented 1 month ago

I'd love to take this up!

monikakuster commented 1 month ago

Hey @sikehish.

If you are new to Bytechef, please read our CONTRIBUTING.md

This part describes how to create new component or how to add new action or trigger to existing one.

Here is the detailed description of the structure of every component.

And finally, here are the guides on how to work with the trigger and how to test it.

sikehish commented 1 month ago

Thank you for the guidance.I am working on it :))

sikehish commented 1 month ago

Implement New Message trigger for Discord component.

Is this channel specific? It's a bit vague. Would you mind explaining it in a bit more detail with regard to what we're trying to achieve here? Would appreciate it!

monikakuster commented 1 month ago

The description for the issue has been updated. I believe it’s clearer now. :)

sikehish commented 1 month ago

The description for the issue has been updated. I believe it’s clearer now. :)

Thank you! Yup, It's a lot clear now!

sikehish commented 1 month ago

The description for the issue has been updated. I believe it’s clearer now. :)

Hi. Am I allowed to use JDA? I am using polling to check for a new message/messages. I just want to confirm if we are on the same page. I have written the logic for this in the below file. If this seems okay, then I shall start incorporating the logic into bytechef. ( https://github.com/sikehish/Discord-New-Message-Trigger/blob/main/src/main/java/org/example/DiscordBot.java)

Also, do I need to create a new type of DiscordConnection , as I'll have to use "Bot " for authorization ? Or would this be deemed as a variant of Bearer token?

marko-kriskovic commented 1 month ago

Hi @sikehish, thank you for asking!

I've skimmed through the code and I don't think that: while(true){ fetchMessages() } is the solution we're looking for. A trigger is Bytechef's name for a webhook. You can see examples in our currently implemented triggers (Box, Google Sheets, Webhook).

Here is how I would approach the problem:

  1. idea would be to find a way to register a webhook to bytechef within discord so that it sends data whenever discord gets a message on the specified channel
  2. idea would be to somehow connect with a Webhook of type "Channel Follower" and Message and call GetChannelMessage in our webhookRequest(...) method
  3. idea would be the same thing as 2. idea, but if I can't get the 'message.id', I could go with GetChannelMessages. Store the number of messages in the channel into our temporary database (see Google Sheets). Return a list of only the new messages (the last (oldNumberOfMessages-newNumberOfMessages) messages).
  4. There is something called a Gateway Event. It could be exactly what we need, but it seems more complicated to implement.

If the JDA could help you with implementing some of these ideas, you are welcome to using it. The Bearer token should be enough for implementing the ideas above, but if it isn't, you are welcome to implement a new type of connection.

Hope this helps :smile: