PureTelegram (framework for using the Telegram API)

Share your advanced PureBasic knowledge/code with the community.
sec
Enthusiast
Enthusiast
Posts: 789
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: PureTelegram (framework for using the Telegram API)

Post by sec »

Nice one!

I have some questions:
- has it support proxy (http, or socks) connection?
- is it multi OS?

Thanks.
infratec
Always Here
Always Here
Posts: 6810
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PureTelegram (framework for using the Telegram API)

Post by infratec »

Since only 'normal' PB HTTP stuff is used, it should be work on all platforms.

If you need a proxy, you have to use

Code: Select all

HTTPProxy()
At the beginning of your code.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: PureTelegram (framework for using the Telegram API)

Post by Seymour Clufley »

This is a radical update of the library, with many changes. Code that uses the library will almost certainly have to be adjusted. For this reason, I have kept a legacy version of the library available (link in OP).

I have overhauled how the GetUpdates system works. It should be simpler to use now, and also more reliable.

There are a lot of new functions.

Most importantly, there is now a help file with a quickstart guide and many code examples, showing how to use each command. I hope this will encourage more people to get up and running with Telegram/PB work.

Full change log:
BUTTONS
Renamed: AddTelegramButton() -> Telegram_AddButton()
Renamed: NewTelegramButtonRow() -> Telegram_NewButtonRow()

POSTING MESSAGES
Renamed: PostMultiplePBImages -> PostAlbumOfPBImages()
Changed: input parameters for PostPBImage()
Changed: input parameters for PostOnlineImage()
Fixed: PostOnlineImage()
Fixed: "protect_content" variable wasn't being correctly handled
Added: "protect_content" variable to PostAlbum(), PostLocation(), PostVenue(), PostContact() and PostPoll()
Changed: PostPoll() can no longer post quizzes
Added: PostQuiz()

EDITING MESSAGES
Added: ReplaceMessageMedia()
Added: ReplaceMessageImageWithPBImage()

CHATS
Added: SetChatDefaultPermissions()
Added: SetChatDefaultPermissionsMap()
Added: SetChatAdministratorPermissionsMap()
Added: SetChatAdministratorCustomTitle()
Added: LeaveChat()

UPDATES
Removed: MyTG\update() list. See NextTelegramUpdate() for how to handle updates now
Changed: InstantiateBot() now requires a folder, not a txt file
Added: NextTelegramUpdate()
Added: DeleteUpdate()
Added: ClearUpdates()
Added: new update types: #TU_Type_MessageWasPinned, #TU_Type_MessageAutoDeleteChange, #TU_Type_Invoice, #TU_Type_SuccessfulPayment and #TU_Type_ProximityAlertTriggered

INVITE LINKS
Added: CreateChatPrimaryInviteLink()

MISC.
Changed: message type constants have been shortened, eg. #Telegram_MessageType_Audio -> #TG_MessageType_Audio
Added: SendStatus()
Added: HTML help file
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: PureTelegram (framework for using the Telegram API)

Post by Seymour Clufley »

Another update, this one focusing on commerce. I also added a few procedures that accidentally weren't included in the previous version.

The commerce functions have been fully tested.
BOTS
Added: MakeScope()
Added: AddBotCommand()
Added: SetBotCommandsForScope()
Added: GetBotCommandsForScope()
Added: DeleteBotCommandsForScope()

COMMERCE
Added: AddInvoiceItem()
Added: PostInvoice()
Added: message type: TG_MessageType_Invoice
Added: AddShippingOption()
Added: AnswerShippingQuery()
Added: AcceptPayment()
Added: DeclinePayment()

WEBHOOKS
Added: SetWebhook()
Added: GetWebhookInfo()
Added: DeleteWebhook()

STICKERS
CreateNewStickerSet(), AddStickerToSet() and UploadStickerFile() now check the file size before uploading

MISC.
Changed: SendStatus() -> SendBotStatus()
I also made a start on InlineMode stuff, but it is so mindbogglingly complicated that I don't think I will pursue it.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Caronte3D
Addict
Addict
Posts: 1014
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PureTelegram (framework for using the Telegram API)

Post by Caronte3D »

Seymour Clufley wrote: Mon Feb 14, 2022 12:22 am I also made a start on InlineMode stuff, but it is so mindbogglingly complicated that I don't think I will pursue it.
I'm sorry to hear that :|
Thanks anyway by all the nice work.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: PureTelegram (framework for using the Telegram API)

Post by Seymour Clufley »

A new version:
Added: DownloadChatAvatar()
Added: DownloadChatAvatarToPBImage()
Changed: DownloadUserProfilePhotosToMemory() -> DownloadUserAvatarsToPBImages()
Changed: DownloadUserProfilePhotos() -> DownloadUserAvatars()
Changed: DownloadUserCurrentProfilePhoto() -> DownloadUserCurrentAvatar()
Changed: removed the word "structure" from the end of all structure names
Fixed: a few bugs with the GetNewUpdates() system
Also, I've begun adding things that Telegram have brought in with the v6.0 API update, but this work is not complete.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
Caronte3D
Addict
Addict
Posts: 1014
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: PureTelegram (framework for using the Telegram API)

Post by Caronte3D »

Thanks for the updates :D
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: PureTelegram (framework for using the Telegram API)

Post by Seymour Clufley »

Caronte3D wrote: Fri Apr 29, 2022 1:40 pm Thanks for the updates :D
Thank you. :)
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
akamicah
User
User
Posts: 18
Joined: Fri May 06, 2022 7:11 pm
Contact:

Re: PureTelegram (framework for using the Telegram API)

Post by akamicah »

Handy!

Couple of points;

Can I ask why are you saving all requests to disk before processing them, also you might want to hide your personal bot API key in the example code :P
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: PureTelegram (framework for using the Telegram API)

Post by Seymour Clufley »

If you mean the updates from Telegram get saved to file... Telegram will only send an update once. If your code crashes before/during processing that update, it won't be able to request it again. Therefore, I thought it was best to save all updates to file before beginning to process them.

My own bot API key isn't in any of the example code, I'm pretty sure.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
akamicah
User
User
Posts: 18
Joined: Fri May 06, 2022 7:11 pm
Contact:

Re: PureTelegram (framework for using the Telegram API)

Post by akamicah »

Seymour Clufley wrote: Thu May 12, 2022 3:44 am If you mean the updates from Telegram get saved to file... Telegram will only send an update once. If your code crashes before/during processing that update, it won't be able to request it again. Therefore, I thought it was best to save all updates to file before beginning to process them.
That's fair
Seymour Clufley wrote: Thu May 12, 2022 3:44 am My own bot API key isn't in any of the example code, I'm pretty sure.
An API token is exposed in a couple of snippets;

https://www.purebasic.fr/english/viewto ... 64#p576464
https://www.purebasic.fr/english/viewto ... 41#p576741
https://www.purebasic.fr/english/viewto ... 81#p576781
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: PureTelegram (framework for using the Telegram API)

Post by Seymour Clufley »

Ah yes, that's a bot key that I just made up, for demo purposes. :)
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
jacdelad
Addict
Addict
Posts: 1418
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: PureTelegram (framework for using the Telegram API)

Post by jacdelad »

Hi Seymour,
I didn't have time to try it, yet and also I didn't have a real reason to use it, but I just wanted to tell you that this Include is very impressive!
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: PureTelegram (framework for using the Telegram API)

Post by Seymour Clufley »

Thank you. :)
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
pozvonok
New User
New User
Posts: 1
Joined: Mon Sep 26, 2022 10:20 am

Re: PureTelegram (framework for using the Telegram API)

Post by pozvonok »

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.
Post Reply