Skip to content

Conversation

@techwithanirudh
Copy link
Owner

@techwithanirudh techwithanirudh commented May 27, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a Discourse-based chatbot with support for chat message and notification event handling.
    • Added AI-powered conversational responses with a custom personality and prompt configuration.
    • Implemented staggered, multi-part message replies for more natural interactions.
    • Integrated rate limiting, Redis caching, and robust logging.
    • Provided utilities for message relevance assessment and time zone formatting.
    • Added comprehensive OpenAPI-generated client SDK for backend API operations.
  • Bug Fixes

    • Improved type definitions and optional property handling for user and tag interfaces.
  • Chores

    • Migrated from Slack to Discourse integration, updating environment variables, documentation, and dependencies.
    • Enhanced .gitignore organization and coverage.
    • Added configuration files for code formatting, linting, and build tools.
    • Updated licensing and project metadata.
  • Refactor

    • Reorganized server utilities, event handlers, and type exports for better maintainability.
    • Removed legacy Slack-related files and configurations.
  • Documentation

    • Updated README title and added a TODO file outlining planned enhancements and known issues.

- Removed unnecessary "paths" configuration from tsconfig.json.
- Changed import statements in chat.ts and webhook.ts to use 'import type' for better clarity and performance.
…date types and OpenAPI specs

- Renamed PostMessageData to SendMessageData and updated related types.
- Refactored response types for sending messages and editing messages.
- Updated OpenAPI specifications to reflect changes in message sending and editing endpoints.
- Adjusted utility functions to use the new sendMessage method.
- Cleaned up unused types and errors in the Zod validation schemas.
- Enhanced response structures for better clarity and consistency.
- Updated generateResponse to include bot creator information.
- Modified handle-app-mention to utilize GetSessionResponse for user identification.
- Enhanced handle-messages to check for keywords and direct messages before processing.
- Refactored slack-utils to accept GetSessionResponse for user identification in getThread.
- Updated OpenAPI specifications to remove unnecessary required fields and improve response descriptions.
- Adjusted package.json build script to streamline the build process.
- Made profile_background_upload_url optional in User interface for better flexibility.
- Removed unused imports of zod and zGetSessionResponse from handle-app-mention.ts, handle-messages.ts, and slack-utils.ts.
- Commented out zod plugin and validator in openapi-ts.config.ts.
- Added new error response codes (400, 403, 429, 500) to openapi.json for improved API documentation.
…ce in message handling; enable zod validation in OpenAPI config; add server restart script
…scourse; enhance package scripts for linting and checking
- Updated import statements in `chat.ts`, `discourse.ts`, `index.ts`, and `webhook.ts` to use single quotes for consistency.
- Removed trailing commas in `tsconfig.json` and adjusted the `exclude` and `include` arrays for clarity.
- Ensured all type definitions in `webhook.ts` are properly formatted and aligned for better readability.
…nt variables

- Created API endpoint that returns "Hello World!"
- Added configuration file with keywords, location, and speed settings
- Implemented environment variable management using zod for validation
- Developed AI response generation logic with weather fetching capability
- Handled app mentions and message processing for AI interactions
- Introduced utility functions for Slack message handling and verification
- Defined types for chat and webhook interactions
- Updated TypeScript configuration for improved compatibility
- Removed obsolete Vercel configuration file
- Updated import paths in events.post.ts for consistency.
- Removed deprecated ai/providers.ts file.
- Added prompts.ts to define various AI prompts for response generation.
- Reintroduced providers.ts with updated structure for AI model integration.
- Created discourse-utils.ts for handling Discourse API interactions.
- Implemented generate-response.ts to manage AI response generation logic.
- Added handle-app-mention.ts to process app mentions and generate responses.
- Created handle-messages.ts to manage incoming chat messages and trigger AI responses.
…tions and chat messages

- Deleted the run.sh script that was used to start the Bun server in a loop.
- Added a new API endpoint at server/api/events/index.post.ts to handle incoming events from Discourse, including app mentions and chat messages.
- Updated tsconfig.json to enable strict null checks for better type safety.
- Updated nitro.config.ts to set esbuild target to "esnext".
- Added new dependencies in package.json for date-fns and compromise.
- Implemented a logger using pino for better logging in various modules.
- Created prompts for AI responses in server/lib/ai/prompts.ts.
- Added AI provider configurations in server/lib/ai/providers.ts.
- Refactored event handling to use the new logger in server/api/events/index.post.ts.
- Updated discourse utility functions to log signature validation and HMAC comparison.
- Enhanced message handling with logging in server/utils/handle-app-mention.ts and server/utils/handle-messages.ts.
- Introduced utility functions for time zone handling in server/utils/time.ts.
- Added message tokenization functions in server/utils/tokenize-messages.ts.
@vercel
Copy link

vercel bot commented May 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ai-sdk-discourse-bot ❌ Failed (Inspect) May 27, 2025 3:29pm

@coderabbitai
Copy link

coderabbitai bot commented May 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update transitions the project from a Slack-based AI chatbot to a Discourse-based chatbot, introducing a new modular server-side architecture. It removes Slack-specific logic and adds comprehensive support for Discourse APIs, event handling, AI-driven response generation, and utilities for rate limiting, logging, and validation. The codebase now features a robust configuration, OpenAPI-generated client SDK, and improved type safety.

Changes

Files/Groups Change Summary
.editorconfig, .npmrc, biome.jsonc, tsconfig.json Added or updated editor, npm, and formatting configurations for consistency and toolchain integration.
.gitignore, LICENSE, TODO.md, README.md Expanded ignores, added AGPL license, project TODOs, and updated documentation for Discourse focus.
.env.example Updated environment variables from Slack to Discourse credentials.
package.json Renamed package, replaced dependencies and scripts for Discourse/Nitro/Biome, removed Slack-related packages.
vercel.json Removed Vercel deployment configuration.
openapi-ts.config.ts, client/* Added OpenAPI codegen config and generated TypeScript client SDK, types, and transformers.
server/config.ts, server/env.ts Added server configuration and environment variable schema with validation.
server/lib/ai/* Introduced AI prompt templates, provider setup, and prompt generation utilities.
server/lib/kv.ts, server/lib/logger.ts Added Redis and rate limiting utilities, and Pino-based logging setup.
server/lib/validators/* Added Zod-based probability schema and validator exports.
server/events/*, server/routes/api/* Implemented modular event handlers for chat messages and notifications, with new API routes for event processing.
server/types/* Added and updated TypeScript interfaces for Discourse/chat/webhook data, with improved type exports.
server/utils/discourse/* Added utilities for Discourse API client, request verification, message/status/user management.
server/utils/generate-response.ts, server/utils/check-relevance.ts, server/utils/staggered-response.ts, server/utils/time.ts, server/utils/tokenize-messages.ts Added AI response generation, relevance checking, staggered message sending, time formatting, and message tokenization utilities.
lib/*, types/*, api/events.ts Deleted all Slack-specific logic, types, and event handlers.

Sequence Diagram(s)

sequenceDiagram
    participant Discourse as Discourse Webhook
    participant API as /api/events.post
    participant Verifier as verifyRequest
    participant BotUser as getBotUser
    participant Events as events[eventType]
    participant AI as generateResponse
    participant DiscourseAPI as sendMessage

    Discourse->>API: POST event (chat_message/notification)
    API->>Verifier: Verify request signature
    Verifier-->>API: Valid/Invalid
    API->>BotUser: Retrieve bot user session
    BotUser-->>API: Bot user
    API->>Events: Find handler for event type
    API->>Events: Execute handler with payload and bot user
    Events->>AI: Generate AI response (if applicable)
    AI-->>Events: AI-generated reply
    Events->>DiscourseAPI: Send reply message
    DiscourseAPI-->>Events: Reply confirmation
    API-->>Discourse: 200 OK / error response
Loading

Poem

A rabbit hops, the code anew,
From Slack to Discourse, fresh and true.
With prompts and bots and rate control,
Redis, logs, and types now whole.
Zenith speaks in slang and jest—
This bunny’s bot now does its best!
🐇✨

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d922537 and 3a781b5.

⛔ Files ignored due to path filters (2)
  • bun.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (53)
  • .editorconfig (1 hunks)
  • .env.example (1 hunks)
  • .gitignore (1 hunks)
  • .npmrc (1 hunks)
  • LICENSE (1 hunks)
  • README.md (1 hunks)
  • TODO.md (1 hunks)
  • api/events.ts (0 hunks)
  • biome.jsonc (1 hunks)
  • client/client.gen.ts (1 hunks)
  • client/index.ts (1 hunks)
  • client/sdk.gen.ts (1 hunks)
  • client/transformers.gen.ts (1 hunks)
  • lib/generate-response.ts (0 hunks)
  • lib/handle-app-mention.ts (0 hunks)
  • lib/handle-messages.ts (0 hunks)
  • lib/slack-utils.ts (0 hunks)
  • lib/utils.ts (0 hunks)
  • nitro.config.ts (1 hunks)
  • openapi-ts.config.ts (1 hunks)
  • package.json (1 hunks)
  • server/config.ts (1 hunks)
  • server/env.ts (1 hunks)
  • server/events/index.ts (1 hunks)
  • server/events/message-create/index.ts (1 hunks)
  • server/events/notification/index.ts (1 hunks)
  • server/lib/ai/prompts.ts (1 hunks)
  • server/lib/ai/providers.ts (1 hunks)
  • server/lib/kv.ts (1 hunks)
  • server/lib/logger.ts (1 hunks)
  • server/lib/validators/index.ts (1 hunks)
  • server/lib/validators/probability.ts (1 hunks)
  • server/routes/api/events.post.ts (1 hunks)
  • server/routes/api/index.ts (1 hunks)
  • server/types/chat.ts (2 hunks)
  • server/types/discourse.ts (3 hunks)
  • server/types/index.ts (1 hunks)
  • server/types/webhook.ts (1 hunks)
  • server/utils/check-relevance.ts (1 hunks)
  • server/utils/discourse/client.ts (1 hunks)
  • server/utils/discourse/index.ts (1 hunks)
  • server/utils/discourse/messages.ts (1 hunks)
  • server/utils/discourse/status.ts (1 hunks)
  • server/utils/discourse/user.ts (1 hunks)
  • server/utils/discourse/verify-request.ts (1 hunks)
  • server/utils/generate-response.ts (1 hunks)
  • server/utils/staggered-response.ts (1 hunks)
  • server/utils/time.ts (1 hunks)
  • server/utils/tokenize-messages.ts (1 hunks)
  • tsconfig.json (1 hunks)
  • types/index.ts (0 hunks)
  • types/webhook.ts (0 hunks)
  • vercel.json (0 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@techwithanirudh techwithanirudh merged commit 6108097 into main May 27, 2025
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant