random_ids are now computed automagically, added methods to ease working with peers and updated docs

This commit is contained in:
Daniil Gentili 2016-12-23 21:06:38 +01:00
parent 1940195949
commit 884232aec3
21 changed files with 167 additions and 61 deletions

View File

@ -200,7 +200,7 @@ $sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message'
var_dump($sentMessage); var_dump($sentMessage);
``` ```
The API class also provides some wrapper methods for logging in as a bot or as a normal user: The API class also provides some wrapper methods for logging in as a bot or as a normal user, and for getting inputPeer constructors to use in sendMessage and other methods:
``` ```
$sentCode = $MadelineProto->phone_login($number); // Send code $sentCode = $MadelineProto->phone_login($number); // Send code
@ -213,6 +213,19 @@ for ($x = 0; $x < $sentCode['type']['length']; $x++) {
$authorization = $MadelineProto->complete_phone_login($code); // Complete authorization $authorization = $MadelineProto->complete_phone_login($code); // Complete authorization
var_dump($authorization); var_dump($authorization);
var_dump($MadelineProto->API->resolve_username('@Palmas2012')); // Always use this method to resolve usernames, but you won't need to call this to get info about peers, as get_peer and get_input_peer will call it for you if needed
$mention = $MadelineProto->API->get_peer('@veetaw'); // Returns an object of type User or Chat
$mention = $MadelineProto->API->constructor2inputpeer($mention); // Converts an object of type User or Chat to an object of type inputPeer
$message = "I've installed MadelineProto!";
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
$peer = $MadelineProto->API->get_input_peer($peer);
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
var_dump($sentMessage);
}
// The above works with bots too
$authorization = $MadelineProto->bot_login($token); // Note that every time you login as a bot or as a user MadelineProto will logout first, so now MadelineProto is logged in as the bot with token $token, not as the user with number $number $authorization = $MadelineProto->bot_login($token); // Note that every time you login as a bot or as a user MadelineProto will logout first, so now MadelineProto is logged in as the bot with token $token, not as the user with number $number
var_dump($authorization); var_dump($authorization);
``` ```

View File

@ -72,7 +72,7 @@ foreach ($TL->methods->method as $key => $method) {
$params = ''; $params = '';
foreach ($TL->methods->params[$key] as $param) { foreach ($TL->methods->params[$key] as $param) {
if ($param['name'] == 'flags') { if (in_array($param['name'], ['flags', 'random_id'])) {
continue; continue;
} }
$stype = 'type'; $stype = 'type';
@ -110,7 +110,7 @@ foreach ($TL->methods->method as $key => $method) {
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
'; ';
foreach ($TL->methods->params[$key] as $param) { foreach ($TL->methods->params[$key] as $param) {
if ($param['name'] == 'flags') { if (in_array($param['name'], ['flags', 'random_id'])) {
continue; continue;
} }
$ptype = str_replace('.', '_', $param[isset($param['subtype']) ? 'subtype' : 'type']); $ptype = str_replace('.', '_', $param[isset($param['subtype']) ? 'subtype' : 'type']);
@ -209,7 +209,7 @@ foreach ($TL->constructors->predicate as $key => $constructor) {
$params = ''; $params = '';
foreach ($TL->constructors->params[$key] as $param) { foreach ($TL->constructors->params[$key] as $param) {
if ($param['name'] == 'flags') { if (in_array($param['name'], ['flags', 'random_id'])) {
continue; continue;
} }
$stype = 'type'; $stype = 'type';
@ -255,7 +255,7 @@ foreach ($TL->constructors->predicate as $key => $constructor) {
'; ';
$params = ''; $params = '';
foreach ($TL->constructors->params[$key] as $param) { foreach ($TL->constructors->params[$key] as $param) {
if ($param['name'] == 'flags') { if (in_array($param['name'], ['flags', 'random_id'])) {
continue; continue;
} }
$ptype = str_replace('.', '_', $param[isset($param['subtype']) ? 'subtype' : 'type']); $ptype = str_replace('.', '_', $param[isset($param['subtype']) ? 'subtype' : 'type']);

View File

@ -11,7 +11,6 @@ description: encryptedMessage attributes, type and example
| Name | Type | Required | | Name | Type | Required |
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|random\_id|[long](../types/long.md) | Required|
|chat\_id|[int](../types/int.md) | Required| |chat\_id|[int](../types/int.md) | Required|
|date|[int](../types/int.md) | Required| |date|[int](../types/int.md) | Required|
|bytes|[bytes](../types/bytes.md) | Required| |bytes|[bytes](../types/bytes.md) | Required|
@ -25,5 +24,5 @@ description: encryptedMessage attributes, type and example
### Example: ### Example:
``` ```
$encryptedMessage = ['_' => encryptedMessage', 'random_id' => long, 'chat_id' => int, 'date' => int, 'bytes' => bytes, 'file' => EncryptedFile, ]; $encryptedMessage = ['_' => encryptedMessage', 'chat_id' => int, 'date' => int, 'bytes' => bytes, 'file' => EncryptedFile, ];
``` ```

View File

@ -11,7 +11,6 @@ description: encryptedMessageService attributes, type and example
| Name | Type | Required | | Name | Type | Required |
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|random\_id|[long](../types/long.md) | Required|
|chat\_id|[int](../types/int.md) | Required| |chat\_id|[int](../types/int.md) | Required|
|date|[int](../types/int.md) | Required| |date|[int](../types/int.md) | Required|
|bytes|[bytes](../types/bytes.md) | Required| |bytes|[bytes](../types/bytes.md) | Required|
@ -24,5 +23,5 @@ description: encryptedMessageService attributes, type and example
### Example: ### Example:
``` ```
$encryptedMessageService = ['_' => encryptedMessageService', 'random_id' => long, 'chat_id' => int, 'date' => int, 'bytes' => bytes, ]; $encryptedMessageService = ['_' => encryptedMessageService', 'chat_id' => int, 'date' => int, 'bytes' => bytes, ];
``` ```

View File

@ -297,10 +297,10 @@ description: List of constructors
<br><br>[$encryptedFileEmpty](../constructors/encryptedFileEmpty.md) = \[\];<a name="encryptedFileEmpty"></a> <br><br>[$encryptedFileEmpty](../constructors/encryptedFileEmpty.md) = \[\];<a name="encryptedFileEmpty"></a>
*** ***
<br><br>[$encryptedMessage](../constructors/encryptedMessage.md) = \['random_id' => [long](../types/long.md), 'chat_id' => [int](../types/int.md), 'date' => [int](../types/int.md), 'bytes' => [bytes](../types/bytes.md), 'file' => [EncryptedFile](../types/EncryptedFile.md), \];<a name="encryptedMessage"></a> <br><br>[$encryptedMessage](../constructors/encryptedMessage.md) = \['chat_id' => [int](../types/int.md), 'date' => [int](../types/int.md), 'bytes' => [bytes](../types/bytes.md), 'file' => [EncryptedFile](../types/EncryptedFile.md), \];<a name="encryptedMessage"></a>
*** ***
<br><br>[$encryptedMessageService](../constructors/encryptedMessageService.md) = \['random_id' => [long](../types/long.md), 'chat_id' => [int](../types/int.md), 'date' => [int](../types/int.md), 'bytes' => [bytes](../types/bytes.md), \];<a name="encryptedMessageService"></a> <br><br>[$encryptedMessageService](../constructors/encryptedMessageService.md) = \['chat_id' => [int](../types/int.md), 'date' => [int](../types/int.md), 'bytes' => [bytes](../types/bytes.md), \];<a name="encryptedMessageService"></a>
*** ***
<br><br>[$error](../constructors/error.md) = \['code' => [int](../types/int.md), 'text' => [string](../types/string.md), \];<a name="error"></a> <br><br>[$error](../constructors/error.md) = \['code' => [int](../types/int.md), 'text' => [string](../types/string.md), \];<a name="error"></a>
@ -1118,7 +1118,7 @@ description: List of constructors
<br><br>[$updateInlineBotCallbackQuery](../constructors/updateInlineBotCallbackQuery.md) = \['query_id' => [long](../types/long.md), 'user_id' => [int](../types/int.md), 'msg_id' => [InputBotInlineMessageID](../types/InputBotInlineMessageID.md), 'chat_instance' => [long](../types/long.md), 'data' => [bytes](../types/bytes.md), 'game_short_name' => [string](../types/string.md), \];<a name="updateInlineBotCallbackQuery"></a> <br><br>[$updateInlineBotCallbackQuery](../constructors/updateInlineBotCallbackQuery.md) = \['query_id' => [long](../types/long.md), 'user_id' => [int](../types/int.md), 'msg_id' => [InputBotInlineMessageID](../types/InputBotInlineMessageID.md), 'chat_instance' => [long](../types/long.md), 'data' => [bytes](../types/bytes.md), 'game_short_name' => [string](../types/string.md), \];<a name="updateInlineBotCallbackQuery"></a>
*** ***
<br><br>[$updateMessageID](../constructors/updateMessageID.md) = \['id' => [int](../types/int.md), 'random_id' => [long](../types/long.md), \];<a name="updateMessageID"></a> <br><br>[$updateMessageID](../constructors/updateMessageID.md) = \['id' => [int](../types/int.md), \];<a name="updateMessageID"></a>
*** ***
<br><br>[$updateNewAuthorization](../constructors/updateNewAuthorization.md) = \['auth_key_id' => [long](../types/long.md), 'date' => [int](../types/int.md), 'device' => [string](../types/string.md), 'location' => [string](../types/string.md), \];<a name="updateNewAuthorization"></a> <br><br>[$updateNewAuthorization](../constructors/updateNewAuthorization.md) = \['auth_key_id' => [long](../types/long.md), 'date' => [int](../types/int.md), 'device' => [string](../types/string.md), 'location' => [string](../types/string.md), \];<a name="updateNewAuthorization"></a>

View File

@ -12,7 +12,6 @@ description: updateMessageID attributes, type and example
| Name | Type | Required | | Name | Type | Required |
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|id|[int](../types/int.md) | Required| |id|[int](../types/int.md) | Required|
|random\_id|[long](../types/long.md) | Required|
@ -22,5 +21,5 @@ description: updateMessageID attributes, type and example
### Example: ### Example:
``` ```
$updateMessageID = ['_' => updateMessageID', 'id' => int, 'random_id' => long, ]; $updateMessageID = ['_' => updateMessageID', 'id' => int, ];
``` ```

View File

@ -242,9 +242,9 @@ $MadelineProto->[messages->editMessage](messages_editMessage.md)(\['no_webpage'
$MadelineProto->[messages->exportChatInvite](messages_exportChatInvite.md)(\['chat_id' => [int](../types/int.md), \]) == [$ExportedChatInvite](../types/ExportedChatInvite.md)<a name="messages_exportChatInvite"></a> $MadelineProto->[messages->exportChatInvite](messages_exportChatInvite.md)(\['chat_id' => [int](../types/int.md), \]) == [$ExportedChatInvite](../types/ExportedChatInvite.md)<a name="messages_exportChatInvite"></a>
$MadelineProto->[messages->forwardMessage](messages_forwardMessage.md)(\['peer' => [InputPeer](../types/InputPeer.md), 'id' => [int](../types/int.md), 'random_id' => [long](../types/long.md), \]) == [$Updates](../types/Updates.md)<a name="messages_forwardMessage"></a> $MadelineProto->[messages->forwardMessage](messages_forwardMessage.md)(\['peer' => [InputPeer](../types/InputPeer.md), 'id' => [int](../types/int.md), \]) == [$Updates](../types/Updates.md)<a name="messages_forwardMessage"></a>
$MadelineProto->[messages->forwardMessages](messages_forwardMessages.md)(\['silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'with_my_score' => [Bool](../types/Bool.md), 'from_peer' => [InputPeer](../types/InputPeer.md), 'id' => \[[int](../types/int.md)\], 'random_id' => \[[long](../types/long.md)\], 'to_peer' => [InputPeer](../types/InputPeer.md), \]) == [$Updates](../types/Updates.md)<a name="messages_forwardMessages"></a> $MadelineProto->[messages->forwardMessages](messages_forwardMessages.md)(\['silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'with_my_score' => [Bool](../types/Bool.md), 'from_peer' => [InputPeer](../types/InputPeer.md), 'id' => \[[int](../types/int.md)\], 'to_peer' => [InputPeer](../types/InputPeer.md), \]) == [$Updates](../types/Updates.md)<a name="messages_forwardMessages"></a>
$MadelineProto->[messages->getAllDrafts](messages_getAllDrafts.md)(\[\]) == [$Updates](../types/Updates.md)<a name="messages_getAllDrafts"></a> $MadelineProto->[messages->getAllDrafts](messages_getAllDrafts.md)(\[\]) == [$Updates](../types/Updates.md)<a name="messages_getAllDrafts"></a>
@ -320,7 +320,7 @@ $MadelineProto->[messages->reorderStickerSets](messages_reorderStickerSets.md)(\
$MadelineProto->[messages->reportSpam](messages_reportSpam.md)(\['peer' => [InputPeer](../types/InputPeer.md), \]) == [$Bool](../types/Bool.md)<a name="messages_reportSpam"></a> $MadelineProto->[messages->reportSpam](messages_reportSpam.md)(\['peer' => [InputPeer](../types/InputPeer.md), \]) == [$Bool](../types/Bool.md)<a name="messages_reportSpam"></a>
$MadelineProto->[messages->requestEncryption](messages_requestEncryption.md)(\['user_id' => [InputUser](../types/InputUser.md), 'random_id' => [int](../types/int.md), 'g_a' => [bytes](../types/bytes.md), \]) == [$EncryptedChat](../types/EncryptedChat.md)<a name="messages_requestEncryption"></a> $MadelineProto->[messages->requestEncryption](messages_requestEncryption.md)(\['user_id' => [InputUser](../types/InputUser.md), 'g_a' => [bytes](../types/bytes.md), \]) == [$EncryptedChat](../types/EncryptedChat.md)<a name="messages_requestEncryption"></a>
$MadelineProto->[messages->saveDraft](messages_saveDraft.md)(\['no_webpage' => [Bool](../types/Bool.md), 'reply_to_msg_id' => [int](../types/int.md), 'peer' => [InputPeer](../types/InputPeer.md), 'message' => [string](../types/string.md), 'entities' => \[[MessageEntity](../types/MessageEntity.md)\], \]) == [$Bool](../types/Bool.md)<a name="messages_saveDraft"></a> $MadelineProto->[messages->saveDraft](messages_saveDraft.md)(\['no_webpage' => [Bool](../types/Bool.md), 'reply_to_msg_id' => [int](../types/int.md), 'peer' => [InputPeer](../types/InputPeer.md), 'message' => [string](../types/string.md), 'entities' => \[[MessageEntity](../types/MessageEntity.md)\], \]) == [$Bool](../types/Bool.md)<a name="messages_saveDraft"></a>
@ -334,17 +334,17 @@ $MadelineProto->[messages->searchGifs](messages_searchGifs.md)(\['q' => [string]
$MadelineProto->[messages->searchGlobal](messages_searchGlobal.md)(\['q' => [string](../types/string.md), 'offset_date' => [int](../types/int.md), 'offset_peer' => [InputPeer](../types/InputPeer.md), 'offset_id' => [int](../types/int.md), 'limit' => [int](../types/int.md), \]) == [$messages\_Messages](../types/messages_Messages.md)<a name="messages_searchGlobal"></a> $MadelineProto->[messages->searchGlobal](messages_searchGlobal.md)(\['q' => [string](../types/string.md), 'offset_date' => [int](../types/int.md), 'offset_peer' => [InputPeer](../types/InputPeer.md), 'offset_id' => [int](../types/int.md), 'limit' => [int](../types/int.md), \]) == [$messages\_Messages](../types/messages_Messages.md)<a name="messages_searchGlobal"></a>
$MadelineProto->[messages->sendEncrypted](messages_sendEncrypted.md)(\['peer' => [InputEncryptedChat](../types/InputEncryptedChat.md), 'random_id' => [long](../types/long.md), 'data' => [bytes](../types/bytes.md), \]) == [$messages\_SentEncryptedMessage](../types/messages_SentEncryptedMessage.md)<a name="messages_sendEncrypted"></a> $MadelineProto->[messages->sendEncrypted](messages_sendEncrypted.md)(\['peer' => [InputEncryptedChat](../types/InputEncryptedChat.md), 'data' => [bytes](../types/bytes.md), \]) == [$messages\_SentEncryptedMessage](../types/messages_SentEncryptedMessage.md)<a name="messages_sendEncrypted"></a>
$MadelineProto->[messages->sendEncryptedFile](messages_sendEncryptedFile.md)(\['peer' => [InputEncryptedChat](../types/InputEncryptedChat.md), 'random_id' => [long](../types/long.md), 'data' => [bytes](../types/bytes.md), 'file' => [InputEncryptedFile](../types/InputEncryptedFile.md), \]) == [$messages\_SentEncryptedMessage](../types/messages_SentEncryptedMessage.md)<a name="messages_sendEncryptedFile"></a> $MadelineProto->[messages->sendEncryptedFile](messages_sendEncryptedFile.md)(\['peer' => [InputEncryptedChat](../types/InputEncryptedChat.md), 'data' => [bytes](../types/bytes.md), 'file' => [InputEncryptedFile](../types/InputEncryptedFile.md), \]) == [$messages\_SentEncryptedMessage](../types/messages_SentEncryptedMessage.md)<a name="messages_sendEncryptedFile"></a>
$MadelineProto->[messages->sendEncryptedService](messages_sendEncryptedService.md)(\['peer' => [InputEncryptedChat](../types/InputEncryptedChat.md), 'random_id' => [long](../types/long.md), 'data' => [bytes](../types/bytes.md), \]) == [$messages\_SentEncryptedMessage](../types/messages_SentEncryptedMessage.md)<a name="messages_sendEncryptedService"></a> $MadelineProto->[messages->sendEncryptedService](messages_sendEncryptedService.md)(\['peer' => [InputEncryptedChat](../types/InputEncryptedChat.md), 'data' => [bytes](../types/bytes.md), \]) == [$messages\_SentEncryptedMessage](../types/messages_SentEncryptedMessage.md)<a name="messages_sendEncryptedService"></a>
$MadelineProto->[messages->sendInlineBotResult](messages_sendInlineBotResult.md)(\['silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'clear_draft' => [Bool](../types/Bool.md), 'peer' => [InputPeer](../types/InputPeer.md), 'reply_to_msg_id' => [int](../types/int.md), 'random_id' => [long](../types/long.md), 'query_id' => [long](../types/long.md), 'id' => [string](../types/string.md), \]) == [$Updates](../types/Updates.md)<a name="messages_sendInlineBotResult"></a> $MadelineProto->[messages->sendInlineBotResult](messages_sendInlineBotResult.md)(\['silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'clear_draft' => [Bool](../types/Bool.md), 'peer' => [InputPeer](../types/InputPeer.md), 'reply_to_msg_id' => [int](../types/int.md), 'query_id' => [long](../types/long.md), 'id' => [string](../types/string.md), \]) == [$Updates](../types/Updates.md)<a name="messages_sendInlineBotResult"></a>
$MadelineProto->[messages->sendMedia](messages_sendMedia.md)(\['silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'clear_draft' => [Bool](../types/Bool.md), 'peer' => [InputPeer](../types/InputPeer.md), 'reply_to_msg_id' => [int](../types/int.md), 'media' => [InputMedia](../types/InputMedia.md), 'random_id' => [long](../types/long.md), 'reply_markup' => [ReplyMarkup](../types/ReplyMarkup.md), \]) == [$Updates](../types/Updates.md)<a name="messages_sendMedia"></a> $MadelineProto->[messages->sendMedia](messages_sendMedia.md)(\['silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'clear_draft' => [Bool](../types/Bool.md), 'peer' => [InputPeer](../types/InputPeer.md), 'reply_to_msg_id' => [int](../types/int.md), 'media' => [InputMedia](../types/InputMedia.md), 'reply_markup' => [ReplyMarkup](../types/ReplyMarkup.md), \]) == [$Updates](../types/Updates.md)<a name="messages_sendMedia"></a>
$MadelineProto->[messages->sendMessage](messages_sendMessage.md)(\['no_webpage' => [Bool](../types/Bool.md), 'silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'clear_draft' => [Bool](../types/Bool.md), 'peer' => [InputPeer](../types/InputPeer.md), 'reply_to_msg_id' => [int](../types/int.md), 'message' => [string](../types/string.md), 'random_id' => [long](../types/long.md), 'reply_markup' => [ReplyMarkup](../types/ReplyMarkup.md), 'entities' => \[[MessageEntity](../types/MessageEntity.md)\], \]) == [$Updates](../types/Updates.md)<a name="messages_sendMessage"></a> $MadelineProto->[messages->sendMessage](messages_sendMessage.md)(\['no_webpage' => [Bool](../types/Bool.md), 'silent' => [Bool](../types/Bool.md), 'background' => [Bool](../types/Bool.md), 'clear_draft' => [Bool](../types/Bool.md), 'peer' => [InputPeer](../types/InputPeer.md), 'reply_to_msg_id' => [int](../types/int.md), 'message' => [string](../types/string.md), 'reply_markup' => [ReplyMarkup](../types/ReplyMarkup.md), 'entities' => \[[MessageEntity](../types/MessageEntity.md)\], \]) == [$Updates](../types/Updates.md)<a name="messages_sendMessage"></a>
$MadelineProto->[messages->setBotCallbackAnswer](messages_setBotCallbackAnswer.md)(\['alert' => [Bool](../types/Bool.md), 'query_id' => [long](../types/long.md), 'message' => [string](../types/string.md), 'url' => [string](../types/string.md), \]) == [$Bool](../types/Bool.md)<a name="messages_setBotCallbackAnswer"></a> $MadelineProto->[messages->setBotCallbackAnswer](messages_setBotCallbackAnswer.md)(\['alert' => [Bool](../types/Bool.md), 'query_id' => [long](../types/long.md), 'message' => [string](../types/string.md), 'url' => [string](../types/string.md), \]) == [$Bool](../types/Bool.md)<a name="messages_setBotCallbackAnswer"></a>
@ -358,7 +358,7 @@ $MadelineProto->[messages->setInlineGameScore](messages_setInlineGameScore.md)(\
$MadelineProto->[messages->setTyping](messages_setTyping.md)(\['peer' => [InputPeer](../types/InputPeer.md), 'action' => [SendMessageAction](../types/SendMessageAction.md), \]) == [$Bool](../types/Bool.md)<a name="messages_setTyping"></a> $MadelineProto->[messages->setTyping](messages_setTyping.md)(\['peer' => [InputPeer](../types/InputPeer.md), 'action' => [SendMessageAction](../types/SendMessageAction.md), \]) == [$Bool](../types/Bool.md)<a name="messages_setTyping"></a>
$MadelineProto->[messages->startBot](messages_startBot.md)(\['bot' => [InputUser](../types/InputUser.md), 'peer' => [InputPeer](../types/InputPeer.md), 'random_id' => [long](../types/long.md), 'start_param' => [string](../types/string.md), \]) == [$Updates](../types/Updates.md)<a name="messages_startBot"></a> $MadelineProto->[messages->startBot](messages_startBot.md)(\['bot' => [InputUser](../types/InputUser.md), 'peer' => [InputPeer](../types/InputPeer.md), 'start_param' => [string](../types/string.md), \]) == [$Updates](../types/Updates.md)<a name="messages_startBot"></a>
$MadelineProto->[messages->toggleChatAdmins](messages_toggleChatAdmins.md)(\['chat_id' => [int](../types/int.md), 'enabled' => [Bool](../types/Bool.md), \]) == [$Updates](../types/Updates.md)<a name="messages_toggleChatAdmins"></a> $MadelineProto->[messages->toggleChatAdmins](messages_toggleChatAdmins.md)(\['chat_id' => [int](../types/int.md), 'enabled' => [Bool](../types/Bool.md), \]) == [$Updates](../types/Updates.md)<a name="messages_toggleChatAdmins"></a>

View File

@ -12,7 +12,6 @@ description: messages_forwardMessage parameters, return type and example
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|peer|[InputPeer](../types/InputPeer.md) | Required| |peer|[InputPeer](../types/InputPeer.md) | Required|
|id|[int](../types/int.md) | Required| |id|[int](../types/int.md) | Required|
|random\_id|[long](../types/long.md) | Required|
### Return type: [Updates](../types/Updates.md) ### Return type: [Updates](../types/Updates.md)
@ -35,5 +34,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$Updates = $MadelineProto->messages->forwardMessage(['peer' => InputPeer, 'id' => int, 'random_id' => long, ]); $Updates = $MadelineProto->messages->forwardMessage(['peer' => InputPeer, 'id' => int, ]);
``` ```

View File

@ -15,7 +15,6 @@ description: messages_forwardMessages parameters, return type and example
|with\_my\_score|[Bool](../types/Bool.md) | Optional| |with\_my\_score|[Bool](../types/Bool.md) | Optional|
|from\_peer|[InputPeer](../types/InputPeer.md) | Required| |from\_peer|[InputPeer](../types/InputPeer.md) | Required|
|id|Array of [int](../types/int.md) | Required| |id|Array of [int](../types/int.md) | Required|
|random\_id|Array of [long](../types/long.md) | Required|
|to\_peer|[InputPeer](../types/InputPeer.md) | Required| |to\_peer|[InputPeer](../types/InputPeer.md) | Required|
@ -39,5 +38,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$Updates = $MadelineProto->messages->forwardMessages(['silent' => Bool, 'background' => Bool, 'with_my_score' => Bool, 'from_peer' => InputPeer, 'id' => [int], 'random_id' => [long], 'to_peer' => InputPeer, ]); $Updates = $MadelineProto->messages->forwardMessages(['silent' => Bool, 'background' => Bool, 'with_my_score' => Bool, 'from_peer' => InputPeer, 'id' => [int], 'to_peer' => InputPeer, ]);
``` ```

View File

@ -11,7 +11,6 @@ description: messages_requestEncryption parameters, return type and example
| Name | Type | Required | | Name | Type | Required |
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|user\_id|[InputUser](../types/InputUser.md) | Required| |user\_id|[InputUser](../types/InputUser.md) | Required|
|random\_id|[int](../types/int.md) | Required|
|g\_a|[bytes](../types/bytes.md) | Required| |g\_a|[bytes](../types/bytes.md) | Required|
@ -35,5 +34,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$EncryptedChat = $MadelineProto->messages->requestEncryption(['user_id' => InputUser, 'random_id' => int, 'g_a' => bytes, ]); $EncryptedChat = $MadelineProto->messages->requestEncryption(['user_id' => InputUser, 'g_a' => bytes, ]);
``` ```

View File

@ -11,7 +11,6 @@ description: messages_sendEncrypted parameters, return type and example
| Name | Type | Required | | Name | Type | Required |
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|peer|[InputEncryptedChat](../types/InputEncryptedChat.md) | Required| |peer|[InputEncryptedChat](../types/InputEncryptedChat.md) | Required|
|random\_id|[long](../types/long.md) | Required|
|data|[bytes](../types/bytes.md) | Required| |data|[bytes](../types/bytes.md) | Required|
@ -35,5 +34,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$messages_SentEncryptedMessage = $MadelineProto->messages->sendEncrypted(['peer' => InputEncryptedChat, 'random_id' => long, 'data' => bytes, ]); $messages_SentEncryptedMessage = $MadelineProto->messages->sendEncrypted(['peer' => InputEncryptedChat, 'data' => bytes, ]);
``` ```

View File

@ -11,7 +11,6 @@ description: messages_sendEncryptedFile parameters, return type and example
| Name | Type | Required | | Name | Type | Required |
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|peer|[InputEncryptedChat](../types/InputEncryptedChat.md) | Required| |peer|[InputEncryptedChat](../types/InputEncryptedChat.md) | Required|
|random\_id|[long](../types/long.md) | Required|
|data|[bytes](../types/bytes.md) | Required| |data|[bytes](../types/bytes.md) | Required|
|file|[InputEncryptedFile](../types/InputEncryptedFile.md) | Required| |file|[InputEncryptedFile](../types/InputEncryptedFile.md) | Required|
@ -36,5 +35,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$messages_SentEncryptedMessage = $MadelineProto->messages->sendEncryptedFile(['peer' => InputEncryptedChat, 'random_id' => long, 'data' => bytes, 'file' => InputEncryptedFile, ]); $messages_SentEncryptedMessage = $MadelineProto->messages->sendEncryptedFile(['peer' => InputEncryptedChat, 'data' => bytes, 'file' => InputEncryptedFile, ]);
``` ```

View File

@ -11,7 +11,6 @@ description: messages_sendEncryptedService parameters, return type and example
| Name | Type | Required | | Name | Type | Required |
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|peer|[InputEncryptedChat](../types/InputEncryptedChat.md) | Required| |peer|[InputEncryptedChat](../types/InputEncryptedChat.md) | Required|
|random\_id|[long](../types/long.md) | Required|
|data|[bytes](../types/bytes.md) | Required| |data|[bytes](../types/bytes.md) | Required|
@ -35,5 +34,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$messages_SentEncryptedMessage = $MadelineProto->messages->sendEncryptedService(['peer' => InputEncryptedChat, 'random_id' => long, 'data' => bytes, ]); $messages_SentEncryptedMessage = $MadelineProto->messages->sendEncryptedService(['peer' => InputEncryptedChat, 'data' => bytes, ]);
``` ```

View File

@ -15,7 +15,6 @@ description: messages_sendInlineBotResult parameters, return type and example
|clear\_draft|[Bool](../types/Bool.md) | Optional| |clear\_draft|[Bool](../types/Bool.md) | Optional|
|peer|[InputPeer](../types/InputPeer.md) | Required| |peer|[InputPeer](../types/InputPeer.md) | Required|
|reply\_to\_msg\_id|[int](../types/int.md) | Optional| |reply\_to\_msg\_id|[int](../types/int.md) | Optional|
|random\_id|[long](../types/long.md) | Required|
|query\_id|[long](../types/long.md) | Required| |query\_id|[long](../types/long.md) | Required|
|id|[string](../types/string.md) | Required| |id|[string](../types/string.md) | Required|
@ -40,5 +39,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$Updates = $MadelineProto->messages->sendInlineBotResult(['silent' => Bool, 'background' => Bool, 'clear_draft' => Bool, 'peer' => InputPeer, 'reply_to_msg_id' => int, 'random_id' => long, 'query_id' => long, 'id' => string, ]); $Updates = $MadelineProto->messages->sendInlineBotResult(['silent' => Bool, 'background' => Bool, 'clear_draft' => Bool, 'peer' => InputPeer, 'reply_to_msg_id' => int, 'query_id' => long, 'id' => string, ]);
``` ```

View File

@ -16,7 +16,6 @@ description: messages_sendMedia parameters, return type and example
|peer|[InputPeer](../types/InputPeer.md) | Required| |peer|[InputPeer](../types/InputPeer.md) | Required|
|reply\_to\_msg\_id|[int](../types/int.md) | Optional| |reply\_to\_msg\_id|[int](../types/int.md) | Optional|
|media|[InputMedia](../types/InputMedia.md) | Required| |media|[InputMedia](../types/InputMedia.md) | Required|
|random\_id|[long](../types/long.md) | Required|
|reply\_markup|[ReplyMarkup](../types/ReplyMarkup.md) | Optional| |reply\_markup|[ReplyMarkup](../types/ReplyMarkup.md) | Optional|
@ -40,5 +39,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$Updates = $MadelineProto->messages->sendMedia(['silent' => Bool, 'background' => Bool, 'clear_draft' => Bool, 'peer' => InputPeer, 'reply_to_msg_id' => int, 'media' => InputMedia, 'random_id' => long, 'reply_markup' => ReplyMarkup, ]); $Updates = $MadelineProto->messages->sendMedia(['silent' => Bool, 'background' => Bool, 'clear_draft' => Bool, 'peer' => InputPeer, 'reply_to_msg_id' => int, 'media' => InputMedia, 'reply_markup' => ReplyMarkup, ]);
``` ```

View File

@ -17,7 +17,6 @@ description: messages_sendMessage parameters, return type and example
|peer|[InputPeer](../types/InputPeer.md) | Required| |peer|[InputPeer](../types/InputPeer.md) | Required|
|reply\_to\_msg\_id|[int](../types/int.md) | Optional| |reply\_to\_msg\_id|[int](../types/int.md) | Optional|
|message|[string](../types/string.md) | Required| |message|[string](../types/string.md) | Required|
|random\_id|[long](../types/long.md) | Required|
|reply\_markup|[ReplyMarkup](../types/ReplyMarkup.md) | Optional| |reply\_markup|[ReplyMarkup](../types/ReplyMarkup.md) | Optional|
|entities|Array of [MessageEntity](../types/MessageEntity.md) | Optional| |entities|Array of [MessageEntity](../types/MessageEntity.md) | Optional|
@ -42,5 +41,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$Updates = $MadelineProto->messages->sendMessage(['no_webpage' => Bool, 'silent' => Bool, 'background' => Bool, 'clear_draft' => Bool, 'peer' => InputPeer, 'reply_to_msg_id' => int, 'message' => string, 'random_id' => long, 'reply_markup' => ReplyMarkup, 'entities' => [MessageEntity], ]); $Updates = $MadelineProto->messages->sendMessage(['no_webpage' => Bool, 'silent' => Bool, 'background' => Bool, 'clear_draft' => Bool, 'peer' => InputPeer, 'reply_to_msg_id' => int, 'message' => string, 'reply_markup' => ReplyMarkup, 'entities' => [MessageEntity], ]);
``` ```

View File

@ -12,7 +12,6 @@ description: messages_startBot parameters, return type and example
|----------|:-------------:|---------:| |----------|:-------------:|---------:|
|bot|[InputUser](../types/InputUser.md) | Required| |bot|[InputUser](../types/InputUser.md) | Required|
|peer|[InputPeer](../types/InputPeer.md) | Required| |peer|[InputPeer](../types/InputPeer.md) | Required|
|random\_id|[long](../types/long.md) | Required|
|start\_param|[string](../types/string.md) | Required| |start\_param|[string](../types/string.md) | Required|
@ -36,5 +35,5 @@ if (isset($number)) {
$MadelineProto->complete_phone_login($code); $MadelineProto->complete_phone_login($code);
} }
$Updates = $MadelineProto->messages->startBot(['bot' => InputUser, 'peer' => InputPeer, 'random_id' => long, 'start_param' => string, ]); $Updates = $MadelineProto->messages->startBot(['bot' => InputUser, 'peer' => InputPeer, 'start_param' => string, ]);
``` ```

View File

@ -204,7 +204,7 @@ $sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message'
var_dump($sentMessage); var_dump($sentMessage);
``` ```
The API class also provides some wrapper methods for logging in as a bot or as a normal user: The API class also provides some wrapper methods for logging in as a bot or as a normal user, and for getting inputPeer constructors to use in sendMessage and other methods:
``` ```
$sentCode = $MadelineProto->phone_login($number); // Send code $sentCode = $MadelineProto->phone_login($number); // Send code
@ -217,6 +217,19 @@ for ($x = 0; $x < $sentCode['type']['length']; $x++) {
$authorization = $MadelineProto->complete_phone_login($code); // Complete authorization $authorization = $MadelineProto->complete_phone_login($code); // Complete authorization
var_dump($authorization); var_dump($authorization);
var_dump($MadelineProto->API->resolve_username('@Palmas2012')); // Always use this method to resolve usernames, but you won't need to call this to get info about peers, as get_peer and get_input_peer will call it for you if needed
$mention = $MadelineProto->API->get_peer('@veetaw'); // Returns an object of type User or Chat
$mention = $MadelineProto->API->constructor2inputpeer($mention); // Converts an object of type User or Chat to an object of type inputPeer
$message = "I've installed MadelineProto!";
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
$peer = $MadelineProto->API->get_input_peer($peer);
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'entities' => [['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
var_dump($sentMessage);
}
// The above works with bots too
$authorization = $MadelineProto->bot_login($token); // Note that every time you login as a bot or as a user MadelineProto will logout first, so now MadelineProto is logged in as the bot with token $token, not as the user with number $number $authorization = $MadelineProto->bot_login($token); // Note that every time you login as a bot or as a user MadelineProto will logout first, so now MadelineProto is logged in as the bot with token $token, not as the user with number $number
var_dump($authorization); var_dump($authorization);
``` ```

View File

@ -18,15 +18,90 @@ namespace danog\MadelineProto\MTProtoTools;
trait PeerHandler trait PeerHandler
{ {
public $chats = []; public $chats = [];
public $users = [];
public function add_users($users) public function add_users($users)
{ {
var_dump($users); foreach ($users as $key => $user) {
switch ($user['_']) {
case 'user':
$this->chats[$user['id']] = $user;
case 'userEmpty':
break;
default:
throw new \danog\MadelineProto\Exception('Invalid user provided at key '.$key.': '.var_export($user, true));
break;
}
}
} }
public function add_chats($chats) public function add_chats($chats)
{ {
var_dump($chats); foreach ($chats as $key => $chat) {
switch ($chat['_']) {
case 'chat':
case 'chatEmpty':
$this->chats[-$chat['id']] = $chat;
case 'chatForbidden':
case 'channelEmpty':
break;
case 'channel':
$this->chats[(int)('-100'.$chat['id'])] = $chat;
break;
default:
throw new \danog\MadelineProto\Exception('Invalid chat provided at key '.$key.': '.var_export($chat, true));
break;
}
}
} }
public function get_peer($id, $recursive = true) {
if (is_numeric($id)) {
if (isset($this->chats[$id])) {
return $this->chats[$id];
}
// if ($recursive) {
// }
throw new \danog\MadelineProto\Exception("Couldn't find peer by provided chat id ".$id);
}
$id = str_replace('@', '', $id);
foreach ($this->chats as $chat) {
if (isset($chat['username']) && $chat['username'] == $id) {
return $chat;
}
}
if ($recursive) {
$this->resolve_username($id);
return $this->get_peer($id, false);
}
throw new \danog\MadelineProto\Exception("Couldn't find peer by provided username ".$id);
}
public function get_input_peer($id) {
return $this->constructor2inputpeer($this->get_peer($id));
}
public function constructor2inputpeer($peer) {
switch ($peer['_']) {
case 'user':
return $peer['self'] ? ['_' => 'inputPeerSelf'] : ['_' => 'inputPeerUser', 'user_id' => $peer['id'], 'access_hash' => $peer['access_hash']];
case 'chat':
case 'chatEmpty':
return ['_' => 'inputPeerChat', 'chat_id' => $peer['id']];
case 'channel':
return ['_' => 'inputPeerChannel', 'channel_id' => $peer['id'], 'access_hash' => $peer['access_hash']];
default:
throw new \danog\MadelineProto\Exception('Invalid constructor given');
}
}
public function resolve_username($username) {
$res = $this->method_call('contacts.resolveUsername', ['username' => str_replace('@', '', $username)]);
if ($res['_'] == 'contacts.resolvedPeer') {
$this->add_users($res['users']);
$this->add_chats($res['chats']);
return $res;
}
throw new \danog\MadelineProto\Exception('resolve_username returned an unexpected constructor: '.var_export($username, true));
}
} }

View File

@ -207,6 +207,23 @@ class TL extends \danog\MadelineProto\Tools
//\danog\MadelineProto\Logger::log('Skipping '.$current_argument['name'].' of type '.$current_argument['type'].'/'.$current_argument['subtype']); //\danog\MadelineProto\Logger::log('Skipping '.$current_argument['name'].' of type '.$current_argument['type'].'/'.$current_argument['subtype']);
continue; continue;
} }
if ($current_argument['name'] == 'random_id') {
switch ($current_argument['type']) {
case 'long':
$serialized .= \phpseclib\Crypt\Random::string(8);
continue 2;
case 'long':
$serialized .= \phpseclib\Crypt\Random::string(4);
continue 2;
case 'Vector t':
if ($method == 'messages.forwardMessages') {
$serialized .= \danog\PHP\Struct::pack('<i', $this->constructors->find_by_predicate('vector')['id']);
$serialized .= \danog\PHP\Struct::pack('<i', count($arguments['id']));
$serialized .= \phpseclib\Crypt\Random::string(8*count($arguments['id']));
continue 2;
}
}
}
throw new Exception('Missing required parameter ('.$current_argument['name'].')'); throw new Exception('Missing required parameter ('.$current_argument['name'].')');
} }
//\danog\MadelineProto\Logger::log('Serializing '.$current_argument['name'].' of type '.$current_argument['type'].'/'.$current_argument['subtype']); //\danog\MadelineProto\Logger::log('Serializing '.$current_argument['name'].' of type '.$current_argument['type'].'/'.$current_argument['subtype']);

View File

@ -38,16 +38,18 @@ if (file_exists('number.php') && !file_exists('session.madeline')) {
echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL; echo 'Deserializing MadelineProto from session.madeline...'.PHP_EOL;
$MadelineProto = unserialize(file_get_contents('session.madeline')); $MadelineProto = unserialize(file_get_contents('session.madeline'));
$message = (getenv('TRAVIS_COMMIT') == '') ? 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION')); $message = (getenv('TRAVIS_COMMIT') == '') ? 'Message entities can be sent too (yay)' : ('Travis ci tests in progress: commit '.getenv('TRAVIS_COMMIT').', job '.getenv('TRAVIS_JOB_NUMBER').', PHP version: '.getenv('TRAVIS_PHP_VERSION'));
$peers = [];
foreach (['pwrtelegramgroup', 'pwrtelegramgroupita'] as $user) {
$username = $MadelineProto->contacts->resolveUsername(['username' => $user]);
var_dump($username);
$peers[$user] = ['_' => 'inputPeerChannel', 'channel_id' => $username['peer']['channel_id'], 'access_hash' => $username['chats'][0]['access_hash']];
}
foreach ($peers as $peer) { $flutter = 'https://storage.pwrtelegram.xyz/pwrtelegrambot/document/file_6570.mp4';
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'random_id' => \danog\PHP\Struct::unpack('<q', \phpseclib\Crypt\Random::string(8))[0]]);
var_dump($MadelineProto->API->resolve_username('@Palmas2012')); // Always use this method to resolve usernames, but you won't need to call this to get info about peers, as get_peer and get_input_peer will call it for you if needed
$mention = $MadelineProto->API->get_peer('@veetaw'); // Returns an object of type User or Chat
$mention = $MadelineProto->API->constructor2inputpeer($mention); // Converts an object of type User or Chat to an object of type inputPeer
foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
$peer = $MadelineProto->API->get_input_peer($peer); // Returns directly an inputPeer object, basically does the same thing I've done manually above
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message.' & pony', 'entities' => [['_' => 'messageEntityUrl', 'offset' => strlen($message)+1, 'length' => 6, 'url' => $flutter], ['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
var_dump($sentMessage); var_dump($sentMessage);
} }
@ -58,9 +60,8 @@ if (file_exists('token.php')) {
$authorization = $MadelineProto->bot_login($token); $authorization = $MadelineProto->bot_login($token);
var_dump($authorization); var_dump($authorization);
} }
/* foreach (['@pwrtelegramgroup', '@pwrtelegramgroupita'] as $peer) {
foreach ($peers as $peer) { $peer = $MadelineProto->API->get_input_peer($peer);
$sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message, 'random_id' => \danog\PHP\Struct::unpack('<q', \phpseclib\Crypt\Random::string(8))[0]]); $sentMessage = $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => $message.' & pony', 'entities' => [['_' => 'messageEntityUrl', 'offset' => strlen($message)+1, 'length' => 6, 'url' => $flutter], ['_' => 'inputMessageEntityMentionName', 'offset' => 0, 'length' => strlen($message), 'user_id' => $mention]]]);
var_dump($sentMessage); var_dump($sentMessage);
} }
*/