Hexabot icon indicating copy to clipboard operation
Hexabot copied to clipboard

Feature Request : Develop Discord Channel

Open marrouchi opened this issue 4 months ago • 0 comments

Summary

Implement a new channel handler for Discord, similar to the existing Facebook/Messenger Channel Handler, allowing Hexabot to integrate with Discord for messaging, events, and interaction capabilities. This feature will extend Hexabot's multi-channel capabilities to Discord, enabling a seamless chatbot experience across Discord servers.

Example : https://github.com/KevinNovak/Discord-Bot-TypeScript-Template

Objectives

  • Develop a channel handler for Discord that will manage events and messages between Hexabot and Discord users.
  • Utilize a structure similar to the existing MessengerHandler to maintain consistency in how channels are handled in Hexabot.
  • Ensure compatibility with Discord API, handle events such as messages, reactions, user join/leave, and command invocations.
  • Maintain the plugin architecture to allow easy extension and integration with other Hexabot features.

Key Requirements

  1. Channel Initialization

    • Create a new channel handler (e.g., DiscordHandler) that inherits from ChannelHandler.
    • Initialize the Discord API client, utilizing the necessary credentials from the settings (similar to Graph API for Messenger).
  2. Settings Management

    • Define and manage channel-specific settings such as bot token, server ID, channel IDs, command prefixes, etc.
    • Use SettingService to add/update/remove settings for Discord integration.
  3. Event Handlers

    • Implement event handlers for key Discord events including:
      • Message Received: Handle direct messages and messages in server channels.
      • User Joined/Left: Track users joining or leaving a server.
      • Reaction Added/Removed: Handle emoji reactions to messages.
      • Commands: Define and handle bot commands using a command prefix (e.g., !).
  4. Incoming and Outgoing Messages

    • Implement a method to format incoming Discord messages into a standard format used by Hexabot (StdIncomingMessage).
    • Implement a method to format outgoing messages into a Discord-compatible format, supporting text, embeds, attachments, and mentions.
    • Handle different types of outgoing messages such as quick replies, buttons, and attachments, similar to the methods (_textFormat, _buttonsFormat, etc.) in MessengerHandler.
  5. Webhook Subscription

    • Create methods to subscribe/unsubscribe to Discord events using the Discord Gateway.
    • Implement necessary middleware for validating events from Discord to ensure secure communication.
  6. User Data Fetching

    • Implement a function to fetch and store user profile data (e.g., username, discriminator, avatar URL) when interacting with Discord users.
    • Store this information in a similar manner as getUserData from MessengerHandler.
  7. Logging and Debugging

    • Add proper logging at key steps to facilitate debugging, using the existing LoggerService.
    • Ensure error handling is implemented for all API interactions with Discord.

Technical Considerations

  • Use discord.js or a similar library to interact with the Discord API.
  • Ensure compliance with Discord's rate limits to avoid API bans.
  • Make use of the EventEmitter to trigger events for received messages, commands, and other interactions.

Testing and Validation

  • Implement unit tests for the DiscordHandler methods, including event handling, message formatting, and API interaction.
  • Perform integration testing with a Discord server to ensure events and commands are properly handled.

Documentation

  • Update the README.md with instructions on configuring Discord as a channel.
  • Add documentation for new settings fields required for the Discord channel.
  • Provide examples of common commands and messages that can be used with Discord.

References

  • Existing MessengerHandler implementation.
  • Discord Developer API documentation: https://discord.com/developers/docs/intro

Expected Outcome

Upon completion, Hexabot should support Discord as a messaging channel, allowing users to interact with Hexabot on Discord servers. This feature will add value by extending Hexabot's capabilities to one of the most popular communication platforms.

marrouchi avatar Oct 09 '24 16:10 marrouchi