Page 5 of 7

Re: PureTelegram (framework for using the Telegram API)

Posted: Sun Oct 16, 2022 9:03 pm
by Caronte3D
I think It's not possible.

Re: PureTelegram (framework for using the Telegram API)

Posted: Mon Oct 17, 2022 12:29 am
by Seymour Clufley
pozvonok wrote: Fri Sep 30, 2022 9:07 am Hello. Thanks for your great work.
Can a bot use this API to communicate with the user in a dialogue?
without public chat.
I didn't find how to do it.
The user needs to contact the bot and open a private chat with it.

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Oct 21, 2022 6:26 pm
by Caronte3D
How to use the @username to send message to it in a private chat?

I can't use the "@username" for ChatID get error 400, chat not found, the only way is to use the numeric ID, but that way I must find the number with another bot.

What I'm doing wrong?

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Oct 21, 2022 6:44 pm
by Seymour Clufley
When you say "private chat", do you mean a private group? If you mean a private one-to-one chat with a person, you can't send messages to such a chat using the API.

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Oct 21, 2022 7:18 pm
by Caronte3D
I mean an open chat with my bot.

I can send messages if on my #UserID I use the number, but I can't use the username its self (ex: @myname).

In other words... How to send messages to an user name (not number id)?

Sorry my poor english :?

Re: PureTelegram (framework for using the Telegram API)

Posted: Fri Oct 21, 2022 7:24 pm
by Caronte3D
This works:

Code: Select all

#ChatID = "123456789"
#BotAPIToken = "9999999999:AAE2ZZ1Vq6pbruVnwIxYbo3qrgE58pyaKX8"

        Define txt.s = "SOME TEXT"
        Telegram_PostText(#BotAPIToken,#ChatID,txt)      
This doesn't work:

Code: Select all

#ChatID = "@myName"
#BotAPIToken = "9999999999:AAE2ZZ1Vq6pbruVnwIxYbo3qrgE58pyaKX8"

        Define txt.s = "SOME TEXT"
        Telegram_PostText(#BotAPIToken,#ChatID,txt)  
From your Help:
"In PureTelegram, every command requires an input variable "chat_id". This can be either the chat's ID number or @username, but never its title."

But I can't use the @username, because I get every time an error:
ERROR: *{"ok":false,"error_code":400,"description":"Bad Request: chat not found"}*

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Oct 22, 2022 5:07 am
by Seymour Clufley
What happens if you omit the @ symbol?

Re: PureTelegram (framework for using the Telegram API)

Posted: Sat Oct 22, 2022 1:20 pm
by Caronte3D
Seymour Clufley wrote: Sat Oct 22, 2022 5:07 am What happens if you omit the @ symbol?
I get the same error

Re: PureTelegram (framework for using the Telegram API)

Posted: Sun Oct 23, 2022 7:39 am
by Seymour Clufley
I've just realised, only public chats can have a @username. I think you must have made a mistake - the private chat you're targeting doesn't have a @username.

Re: PureTelegram (framework for using the Telegram API)

Posted: Sun Oct 23, 2022 4:20 pm
by Caronte3D
I don't understand :?

I only want a way to send and receive messages from an user to the bot and viceversa, I do it already with the userID, but no with the @username.

Everything works well If I use de userID number, but in that case I must find that number using another telegram bot: @userinfobot

Re: PureTelegram (framework for using the Telegram API)

Posted: Sun Oct 23, 2022 5:53 pm
by Seymour Clufley
Right, so it's not a group or channel, it's a private chat between a user and the bot. A private chat NEVER has a @username, and you can't send a message to a person by using their personal @username either. You need the numerical ID of the private chat between the user and your bot.

When the bot receives a message, analyse the message and get its chat ID and use that.

Code: Select all

Procedure.b HandleMessagePosted(*u.TG_Update)
  With *u
      If \message\text = "Hello bot."
         txt.s = "Hello user."
         Telegram_PostText(#BotAPIToken,Str(\message\chat\id),txt)
      EndIf
   EndWith
EndProcedure

Re: PureTelegram (framework for using the Telegram API)

Posted: Sun Oct 23, 2022 6:24 pm
by Caronte3D
Oh! Ok, ok... I see now :D
Thanks for your help :wink:

Re: PureTelegram (framework for using the Telegram API)

Posted: Wed Jan 04, 2023 2:35 pm
by Caronte3D
Hi!
If I try to replace an image to a message in a group, the app closes because memory error.
I was expect a "false" value on return in case the message fails to update, so I could send a new message instead.

EDIT: I think doing that without the caption string runs ok :?

Code: Select all

If Not Telegram_ReplaceMessageImageWithPBImage(#BotAPIToken,#ChatID,lastMsgID,image,"caption")
    ultimoMsgID=Telegram_PostPBImage(#BotAPIToken,#ChatID,image,"caption")     
EndIf

Re: PureTelegram (framework for using the Telegram API)

Posted: Thu Jan 05, 2023 6:46 am
by Seymour Clufley
Have you included UsePNGImageEncoder() and UseJPEGImageEncoder() ?

Re: PureTelegram (framework for using the Telegram API)

Posted: Thu Jan 05, 2023 12:44 pm
by Caronte3D
Seymour Clufley wrote: Thu Jan 05, 2023 6:46 am Have you included UsePNGImageEncoder() and UseJPEGImageEncoder() ?
Yes!