Skip to content

Fix: /start command not reaching runtime due to middleware bypass #13

@amirmabhout

Description

@amirmabhout

Problem Description

When a user opens a Telegram bot for the first time and clicks the default /start button, the runtime does not receive any events, preventing the bot from responding to
new users.

Root Cause

The /start command is being handled separately via bot.start() method which bypasses the middleware chain. This causes:

  • The authorization middleware to be skipped
  • The chat and entity setup middleware to be skipped
  • No proper MESSAGE_RECEIVED event being emitted to the runtime

Solution

Remove the separate /start handler and let /start commands flow through the normal message processing pipeline like any other message.

Code Change

In src/service.ts, line 169-176, change from:

private async initializeBot(): Promise<void> {
  this.bot?.start((ctx) => {
    this.runtime.emitEvent([TelegramEventTypes.SLASH_START], {
      // we don't need this
      ctx,
    });
  });
  this.bot?.launch({
    dropPendingUpdates: true,
    allowedUpdates: ['message', 'message_reaction'],
  });

To:

private async initializeBot(): Promise<void> {
  // Remove the separate /start handler to let it flow through normal message processing
  // This ensures /start commands go through middleware and proper initialization
  this.bot?.launch({
    dropPendingUpdates: true,
    allowedUpdates: ['message', 'message_reaction'],
  });

Impact

This fix ensures that when new users click /start:
1. The command goes through authorization middleware
2. The chat and entity middleware creates the world, room, and entities
3. The message handler creates proper memory and emits MESSAGE_RECEIVED event
4. The runtime and plugins can properly respond to the new user

Testing

After this change:
- New users clicking /start will receive responses from the bot
- The /start command will be treated as a regular text message "/start"
- All middleware will process the command properly
- The runtime will receive the expected MESSAGE_RECEIVED event

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions