shady2k / logseq-inbox-telegram-plugin

MIT License
78 stars 5 forks source link

Not Receiving Messages from Bots Sent to a Group #20

Closed harshadwaj closed 2 years ago

harshadwaj commented 2 years ago

Messages from users comes fine but not from those sent from bots.

Example usage - I have setup an iOS shortcut to send message to a telegram group using the api. Those are not delivered to Logseq even though I can see them appear in the group.

Also, the "authorizesUsers":[] is empty to allow message from all users.

shady2k commented 2 years ago

Hello! And how does this iOS shortcut send messages? From which user do they sent? Can you post here its code? Or, maybe, you could create test group with this messages and invite me @shady2k to this group and I've inspect this messages.

harshadwaj commented 2 years ago

I created iOS shortcut to send message to a telegram group instead of opening the app. The shortcut uses the telegram POST API. The format is: https://api.telegram.org/bot<bot-token>/sendMessage as url and body containing two form fields - chat_id and text.

The token used is of the bot and it appears ok in the group as sent by bot. Logseq does not pull these messages.

shady2k commented 2 years ago

You should try:

harshadwaj commented 2 years ago

That is the setting that I have already done to make the bot work as per the instructions. Verified again and its DISABLED. Still no messages from bot only. From user works fine.

shady2k commented 2 years ago

Ok, let's try:

harshadwaj commented 2 years ago

I did some more testing and figured out that it is the constraint of the Telegram API and it has nothing to do with your plugin. In summary, bots cannot read messages from other bots.

However, I am not sure how and why it works in Telegroam. Maybe because of the proxy server?

shady2k commented 2 years ago

I'm not sure. Probably proxy used for work with files from Telegram. Can you do that I was asked you before?

harshadwaj commented 2 years ago

I did and the getUpdates does not fetch messages posted through Shortcut (which is using bot). Returns an empty array as result: [ ]. The reason for that is the official docs link I have posted.

shady2k commented 2 years ago

I have no idea what do with this. I were inspected the code of telegroam, it uses same way to fetch messages from Telegram.

harshadwaj commented 2 years ago

I had to refer to my notes to figure out what I had done to make it work. Telegroam also does not handle this by default. I had updated its code. Here is the summary of what I had done, so that you can update your code to make it work:

  1. Create two bots - a push bot and pull bot
  2. Use pull bot's token to pull (in Telegroam and in future in this plugin) and push bot's token in the iOS Shortcut
  3. Create a channel and add both bots as admins.
  4. Set privacy DISABLED for both bots and make sure add to groups is set to TRUE.
  5. Had changed the code in this line to add channel_post to the list. You have to do something similar to process messages from a channel.
  6. Send a POST message from iOS Shortcut.
  7. Make sure it appears in the channel and through the getUpdates API

This worked in Telegroam and also will work in your plugin because the above restriction I mentioned that bots cannot read bots does not apply to channel messages.

I did these steps again now and I am able to verify the messages from getUpdates API.

shady2k commented 2 years ago

Can you check with new version?

harshadwaj commented 2 years ago

Works perfect now. Getting messages from channel pushed through Shortcut. A minor annoyance (not related to this) is that messages gets added next to the first block in the journal but not at the end of all the blocks.

Otherwise, its working perfectly fine. Thanks for such a quick update.