Leask / halbot

Just another `ChatGPT` / `Gemini` / `Mistral (by ollama)` Telegram bob, which is simple design, easy to use, extendable and fun.
https://leaskh.com/post/711636926789271552/halbot
MIT License
101 stars 16 forks source link

adding bot to group causes error #5

Closed kamil-malinski closed 1 year ago

kamil-malinski commented 1 year ago

Hi!

If I add the bot to a group, the bot crashes:

9|halbot  | /root/halbot/node_modules/telegraf/lib/core/network/client.js:293
9|halbot  |             throw new error_1.default(data, { method, payload });
9|halbot  |                   ^
9|halbot  | TelegramError: 400: Bad Request: chat_id is empty
9|halbot  |     at Telegram.callApi (/root/halbot/node_modules/telegraf/lib/core/network/client.js:293:19)
9|halbot  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
9|halbot  |     at async ctx.ok (file:///root/halbot/node_modules/utilitas/lib/bot.mjs:93:35)
9|halbot  |     at async ok (file:///root/halbot/skills/ai.mjs:32:20) {
9|halbot  |   response: {
9|halbot  |     ok: false,
9|halbot  |     error_code: 400,
9|halbot  |     description: 'Bad Request: chat_id is empty'
9|halbot  |   },
9|halbot  |   on: {
9|halbot  |     method: 'editMessageText',
9|halbot  |     payload: {
9|halbot  |       chat_id: undefined,
9|halbot  |       message_id: 27,
9|halbot  |       inline_message_id: '',
9|halbot  |       reply_to_message_id: undefined,
9|halbot  |       disable_notification: true,
9|halbot  |       onProgress: true,
9|halbot  |       text: 'Hey |'
9|halbot  |     }
9|halbot  |   }
9|halbot  | }
Leask commented 1 year ago

Thanks! I will take a look after work.

Leask commented 1 year ago

Fixed. Please check it out. Thanks for your info.

kamil-malinski commented 1 year ago

thank you for the update

I added the bot to a group and it doesn't respond to anything in the group, even if I directly address the bot

as soon as I make the bot an admin of the group, it crashes with:

file:///root/halbot/node_modules/utilitas/lib/bot.mjs:67
                if (msg.new_chat_member.user === ctx.botInfo.id
                        ^

TypeError: Cannot read properties of undefined (reading 'new_chat_member')
    at file:///root/halbot/node_modules/utilitas/lib/bot.mjs:67:25
    at execute (/root/halbot/node_modules/telegraf/lib/composer.js:485:23)
    at /root/halbot/node_modules/telegraf/lib/composer.js:486:27
    at execute (/root/halbot/node_modules/telegraf/lib/composer.js:485:23)
    at /root/halbot/node_modules/telegraf/lib/composer.js:486:27
    at /root/halbot/node_modules/telegraf/lib/future.js:145:16
    at execute (/root/halbot/node_modules/telegraf/lib/composer.js:485:23)
    at /root/halbot/node_modules/telegraf/lib/composer.js:486:27
    at /root/halbot/node_modules/telegraf/lib/composer.js:161:31
    at execute (/root/halbot/node_modules/telegraf/lib/composer.js:485:23)
kamil-malinski commented 1 year ago

if I restart the bot after I made it admin, it responds in the group, but just once, after that every reply is being ignored and I see

[BOT 2023-03-27T09:25:35.913Z] Missing response.

in the log

Leask commented 1 year ago
TypeError: Cannot read properties of undefined (reading 'new_chat_member')

This is not the right version of utilities. Please update all the depending packages or reinstall the latest halbot. :)

If you see this after you update to the latest version, please come back and let me know, thanks!

Leask commented 1 year ago

if I restart the bot after I made it admin, it responds in the group, but just once, after that every reply is being ignored and I see

[BOT 2023-03-27T09:25:35.913Z] Missing response.

in the log

It's OK to see this line of logs. Because telegram will send lots of system messages to the bot client, not all the messages need to be parsed and replied to. I ignored some of the messages from the system, which will show this log that tell us the bot receiving messages.

Leask commented 1 year ago

@kamil-malinski

1st, You have to give the bot permission to access the messages in the group, which means you need to give the bot admin role. That is a limitation of telegram APIs.

2nd, Halbot will only reply to messages when it has been mentioned in a group, not all the messages by default. You can let it reply to all the messages in a group. That will be a bit crazy, but you can do it if you want by adding the group keyword to the chatType array of the config file.