-
Notifications
You must be signed in to change notification settings - Fork 7
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
New API calls needed in BotAPIfunctions.php #18
Comments
I'm now working on the following functions:
These functions are already present in |
I'm working on the following functions:
|
I have completed the list of the API calls |
@atlas-ark have improved the |
Working on |
Maybe it can be a wrapper for the Implement the changes into the |
Took care of this in #24 with the last commit |
I'll work on the following functions:
|
I'll work on the following functions:
|
I'll work on the following functions:
|
Todo
Description
We should be writing new functions (API call wrappers) in
BotAPIfunctions.php
.The aim should be writing functions with all possible parameters, paying attention to check for the required ones.
Try to target only useful calls, no need to implement them all.
Telegram Bot API documentation
Before start working on this, please comment with the function(s) you're currently coding, so we don't overlap work.
How to write functions
We should be writing functions in a way that will let us use different numbers of parameters very easily, without writing unreadable (and difficult to use) code.
Bitmasks are a perfect tool for this.
This necessity derives directly from the very high number of boolean parameters that the Telegram Bot API lets us use.
We'll not use every single API method and we'll not use every single parameter that the API offers us, but when we do, we'll have the need to specify only some of the optional parameters in a very readable way.
Every wrapper of an API method, that allows the passing of optional (and, for us, useful) parameters, should take a
$flag
parameter, which default value should be0
(zero). This parameter is of typeint
but the value inside will be considered as a binary number.Function declaration:
inginf_bot/basefunctions.php
Line 366 in c6a8fa6
When calling the function from the outside, we will use something like this:
$message = sendMessage($chat_id, $text, ENABLE_PAGE_PREVIEW | DISABLE_NOTIFICATION);
As you can see, the first 2 parameters are the required ones, while the third is optional, with a default value of zero.
When specifying the
$flags
you can see we are making use of the bitwise OR operator applied to some constants defined inconstants.php
.These constants are binary values, each of them representing a boolean feature that we want our function to use.
In the example, we see we want to send the message enabling the link preview while not sending the user a notification. To combine features, it's necessary to use the
|
operator.Features constants look like this:
inginf_bot/constants.php
Lines 23 to 26 in c6a8fa6
Adding a constant is really easy:
<<
operatorA fifth one could look like this:
const SUPPORTS_STREAMING = 1 << 4;
Writing the functions, we have to handle the value generated by the bitmask passed as a parameter while also defining the constants allowed to be passed in the function itself.
Take a look at this snippet of code:
inginf_bot/basefunctions.php
Lines 386 to 399 in c6a8fa6
Using the
&
operator (bitwise AND) we check the presence of the feature in the$flag
parameter, this will let us be able to set internal variables correctly and make the right API call.Main API calls to implement (constantly updating)
The following list is just for reference.
If you find it useful to write different functions for the same API call, please tell us in the comment so we can discuss it.
answerCallbackQuery()
answerInlineQuery()
deleteMessage()
editMessageCaption()
editMessageMedia()
editMessageReplyMarkup()
editMessageText()
exportChatInviteLink()
forwardMessage()
getChat()
getChatAdministrators()
getChatMember()
getFile()
getMe()
kickChatMember()
leaveChat()
pinChatMessage()
promoteChatMember()
restrictChatMember()
setChatPermissions()
sendAnimation()
sendAudio()
sendDocument()
sendMediaGroup()
sendMessage()
sendPhoto()
sendVideo()
sendVoice()
setMyCommands()
unbanChatMember()
unpinChatMessage()
The text was updated successfully, but these errors were encountered: