Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending Messages and Not Seeing Them in the Chat #23

Open
faruk-avci opened this issue Aug 20, 2024 · 2 comments
Open

Sending Messages and Not Seeing Them in the Chat #23

faruk-avci opened this issue Aug 20, 2024 · 2 comments

Comments

@faruk-avci
Copy link

I logged into my account and sent some messages to a chat. Although the response body returns a status code of 200, sometimes I can't see the message in the chat. However, after waiting a bit and sending the message again, it does appear.

I'm not sure why this inconsistency is happening. Has anyone else experienced a similar issue, or could there be a delay in the message processing?

@pwnflakes
Copy link

pwnflakes commented Aug 24, 2024

I encountered this too, but I think part of the issue is that when you get a 200 return code from sending a message, that isn't saying that the message has arrived, it's saying the request to send it has.

When I caught errors explicitly, I could see the underlying error message, usually a kick error like Too many special characters etc (helps to mod the bot). May have to change a few things but the below code had my bot sending the error it retrieved to chat, but you could optionally just log it to console.

  async sendMessage(channel, message) {
    try {
      const targetChannel = this.channels.find(ch => ch.data.chatroom.id === channel);
      if (targetChannel) {
        const response = await this.chat.api.chat.sendMessage(targetChannel.data.chatroom.id, message);
        if (response.status && response.status.error) {
          const { status, code, message: errorMessage } = response.status;
          global.tools.logWithPlatform('kick', `Extracted error details - Status: ${status}, Code: ${code}, Message: ${errorMessage}`);
          throw new KickApiError('Error sending message', status, code, errorMessage);
        }
      }
    } catch (error) {
      //console.dir(error, { depth: null }); <- contents of error object
      global.tools.logWithPlatform('kick', `Error sending message: ${error.message}`);
      const errorMessage = error.cause && error.cause.body && error.cause.body.status
        ? `Error: ${error.cause.body.status.message} (Code: ${error.cause.body.status.code}, Status: ${error.cause.body.status.status})`
        : `Error: ${error.message}`;
      await this.sendMessageToChannel(channel, errorMessage);
    }
  }

@faruk-avci
Copy link
Author

I have 10 bots sending messages to same chatroom and decided to put one second delay and didnt get any error so far. I dont know what changed but it seems fine for me. I will keep monitoring it to make sure it continues properly.

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

No branches or pull requests

2 participants