{"id":46354994,"url":"https://github.com/prog-time/max-php-sdk","last_synced_at":"2026-03-08T21:20:20.917Z","repository":{"id":339856364,"uuid":"1163554378","full_name":"prog-time/max-php-sdk","owner":"prog-time","description":null,"archived":false,"fork":false,"pushed_at":"2026-02-21T22:39:14.000Z","size":51,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-22T04:38:07.357Z","etag":null,"topics":["max","php","sdk"],"latest_commit_sha":null,"homepage":"https://dev.max.ru/docs","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prog-time.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-02-21T20:03:36.000Z","updated_at":"2026-02-21T22:38:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/prog-time/max-php-sdk","commit_stats":null,"previous_names":["prog-time/max-php-sdk"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/prog-time/max-php-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prog-time%2Fmax-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prog-time%2Fmax-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prog-time%2Fmax-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prog-time%2Fmax-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prog-time","download_url":"https://codeload.github.com/prog-time/max-php-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prog-time%2Fmax-php-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30102101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T23:59:36.199Z","status":"ssl_error","status_checked_at":"2026-03-04T23:56:48.556Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["max","php","sdk"],"created_at":"2026-03-05T00:09:21.146Z","updated_at":"2026-03-08T21:20:20.911Z","avatar_url":"https://github.com/prog-time.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Max Bot PHP SDK\n\nPHP SDK for the [Max](https://max.ru) messenger Bot API.\n\n## Requirements\n\n- PHP 8.1+\n- Composer\n\n## Installation\n\n```bash\ncomposer require prog-time/max-php-sdk\n```\n\n## Quick start\n\n```php\nuse MaxBotApi\\MaxClient;\nuse MaxBotApi\\Config;\n\n$client = new MaxClient(new Config('your-bot-token'));\n\n$client-\u003emessages-\u003esend(text: 'Hello!', chatId: 123456789);\n```\n\n## Configuration\n\n```php\n$config = new Config(\n    token:   'your-bot-token',              // required\n    baseUrl: 'https://platform-api.max.ru', // optional, default value\n    timeout: 10,                            // optional, seconds, default 10\n);\n```\n\n---\n\n## Resources\n\n### Bot\n\n```php\n$bot = $client-\u003ebot-\u003eme();\n\necho $bot-\u003ename;\necho $bot-\u003euserId;\necho $bot-\u003eusername;\n```\n\n---\n\n### Messages\n\n**Send a message**\n\n```php\n// to a chat\n$message = $client-\u003emessages-\u003esend(text: 'Hello!', chatId: 123456789);\n\n// to a user (direct message)\n$message = $client-\u003emessages-\u003esend(text: 'Hello!', userId: 987654321);\n\n// with Markdown formatting\n$message = $client-\u003emessages-\u003esend(\n    text:   '**Bold** and _italic_',\n    chatId: 123456789,\n    format: 'markdown',\n);\n```\n\n**Get messages**\n\n```php\n$messages = $client-\u003emessages-\u003elist(chatId: 123456789, count: 20);\n\n$message = $client-\u003emessages-\u003eget('message-id');\n```\n\n**Edit and delete**\n\n```php\n$client-\u003emessages-\u003eedit(messageId: 'message-id', text: 'Updated text');\n\n$client-\u003emessages-\u003edelete('message-id');\n```\n\n**Answer a callback (inline button)**\n\n```php\n$client-\u003emessages-\u003eanswerCallback(\n    callbackId:   $update-\u003epayload['callback']['callback_id'],\n    notification: 'Button pressed!',\n);\n```\n\n---\n\n### Chats\n\n```php\n$chats = $client-\u003echats-\u003elist(count: 50);\n\n$chat  = $client-\u003echats-\u003eget(chatId: 123456789);\n\n$client-\u003echats-\u003eupdate(chatId: 123456789, title: 'New title');\n\n$client-\u003echats-\u003esendAction(chatId: 123456789, action: 'typing_on');\n\n$client-\u003echats-\u003epinMessage(chatId: 123456789, messageId: 'message-id');\n$client-\u003echats-\u003eunpinMessage(chatId: 123456789);\n\n$client-\u003echats-\u003edelete(chatId: 123456789);\n```\n\nAvailable sender actions: `typing_on`, `sending_photo`, `sending_video`, `sending_audio`, `sending_file`, `mark_seen`.\n\n---\n\n### Chat members\n\n```php\n$members = $client-\u003echatMembers-\u003elist(chatId: 123456789);\n$admins  = $client-\u003echatMembers-\u003elistAdmins(chatId: 123456789);\n\n$client-\u003echatMembers-\u003eadd(chatId: 123456789, userIds: [111, 222]);\n$client-\u003echatMembers-\u003eremove(chatId: 123456789, userId: 111);\n$client-\u003echatMembers-\u003eremove(chatId: 123456789, userId: 111, block: true);\n\n$client-\u003echatMembers-\u003eaddAdmin(chatId: 123456789, userId: 111);\n$client-\u003echatMembers-\u003eremoveAdmin(chatId: 123456789, userId: 111);\n\n$me = $client-\u003echatMembers-\u003egetMe(chatId: 123456789);\n$client-\u003echatMembers-\u003eleaveChat(chatId: 123456789);\n```\n\n---\n\n### Subscriptions (webhooks)\n\n```php\n// Subscribe\n$client-\u003esubscriptions-\u003esubscribe(\n    url:         'https://example.com/webhook',\n    updateTypes: ['message_created', 'bot_started'],\n    secret:      'my-secret',\n);\n\n// List active subscriptions\n$subscriptions = $client-\u003esubscriptions-\u003elist();\n\n// Unsubscribe\n$client-\u003esubscriptions-\u003eunsubscribe();\n```\n\n**Long polling** (development only):\n\n```php\n$updates = $client-\u003esubscriptions-\u003egetUpdates(limit: 10, timeout: 30);\n\nforeach ($updates as $update) {\n    echo $update-\u003eupdateType . PHP_EOL;\n    // $update-\u003epayload contains all event-specific fields\n}\n```\n\n---\n\n### Uploads\n\n**Send an image**\n\n```php\nuse MaxBotApi\\Resources\\Uploads;\n\n$token = $client-\u003euploads-\u003euploadFile('/path/to/photo.jpg', Uploads::TYPE_IMAGE);\n\n$client-\u003emessages-\u003esend(\n    text:        'Here is your image!',\n    chatId:      123456789,\n    attachments: [\n        ['type' =\u003e 'image', 'payload' =\u003e ['token' =\u003e $token]],\n    ],\n);\n```\n\n**Send a file (PDF, ZIP, DOCX, …)**\n\n```php\n$token = $client-\u003euploads-\u003euploadFile('/path/to/document.pdf', Uploads::TYPE_FILE);\n\n$client-\u003emessages-\u003esend(\n    text:        'Here is the document.',\n    chatId:      123456789,\n    attachments: [\n        ['type' =\u003e 'file', 'payload' =\u003e ['token' =\u003e $token]],\n    ],\n);\n```\n\n**Send a video or audio**\n\nFor video and audio, the server processes the file asynchronously. If you send the message too quickly you will receive an `attachment.not.ready` error — use exponential back-off:\n\n```php\n$token = $client-\u003euploads-\u003euploadFile('/path/to/movie.mp4', Uploads::TYPE_VIDEO);\n\n$delay    = 2;\n$maxTries = 5;\n\nfor ($attempt = 1; $attempt \u003c= $maxTries; $attempt++) {\n    try {\n        $client-\u003emessages-\u003esend(\n            text:        'Check out this video!',\n            chatId:      123456789,\n            attachments: [\n                ['type' =\u003e 'video', 'payload' =\u003e ['token' =\u003e $token]],\n            ],\n        );\n        break;\n    } catch (\\MaxBotApi\\Exceptions\\ApiException $e) {\n        if ($e-\u003egetMessage() === 'attachment.not.ready' \u0026\u0026 $attempt \u003c $maxTries) {\n            sleep($delay);\n            $delay *= 2;\n        } else {\n            throw $e;\n        }\n    }\n}\n```\n\n**Send multiple images at once**\n\n```php\n$attachments = [];\nforeach (['/path/photo1.jpg', '/path/photo2.jpg'] as $path) {\n    $token         = $client-\u003euploads-\u003euploadFile($path, Uploads::TYPE_IMAGE);\n    $attachments[] = ['type' =\u003e 'image', 'payload' =\u003e ['token' =\u003e $token]];\n}\n\n$client-\u003emessages-\u003esend(text: 'Here are the photos!', chatId: 123456789, attachments: $attachments);\n```\n\n**Low-level: get the upload URL only**\n\n```php\n$result = $client-\u003euploads-\u003egetUploadUrl(Uploads::TYPE_IMAGE);\n// $result-\u003eurl   — upload the file here with your own HTTP client\n// $result-\u003etoken — for video/audio: use this as the attachment token\n```\n\nAvailable types: `Uploads::TYPE_IMAGE`, `TYPE_VIDEO`, `TYPE_AUDIO`, `TYPE_FILE`.\n\n---\n\n## Webhooks\n\n```php\nuse MaxBotApi\\Webhook;\n\n$data   = Webhook::parse();\n$update = \\MaxBotApi\\DTO\\Update::fromArray($data);\n\nswitch ($update-\u003eupdateType) {\n    case 'message_created':\n        $message = $update-\u003epayload['message'];\n        break;\n\n    case 'bot_started':\n        $user = $update-\u003epayload['user'];\n        break;\n\n    case 'message_callback':\n        $callback = $update-\u003epayload['callback'];\n        break;\n}\n```\n\nSupported update types: `message_created`, `message_callback`, `message_edited`, `message_removed`, `bot_started`, `bot_stopped`, `bot_added`, `bot_removed`, `user_added`, `user_removed`, `chat_title_changed`, `message_chat_created`, `message_construction_request`, `message_constructed`.\n\n---\n\n## Error handling\n\n```php\nuse MaxBotApi\\Exceptions\\RateLimitException;\nuse MaxBotApi\\Exceptions\\ApiException;\nuse MaxBotApi\\Exceptions\\NetworkException;\n\ntry {\n    $client-\u003emessages-\u003esend(text: 'Hello!', chatId: 123456789);\n\n} catch (RateLimitException $e) {\n    // HTTP 429 — retry after the specified delay\n    sleep($e-\u003eretryAfter ?? 60);\n\n} catch (ApiException $e) {\n    // HTTP 4xx / 5xx — API returned an error\n    echo $e-\u003egetMessage();\n    echo $e-\u003egetCode(); // HTTP status code\n\n} catch (NetworkException $e) {\n    // Connection failure, timeout, DNS error\n    echo $e-\u003egetMessage();\n}\n```\n\nException hierarchy:\n\n```\n\\RuntimeException\n├── MaxBotApi\\Exceptions\\ApiException        — HTTP 4xx / 5xx\n│   └── MaxBotApi\\Exceptions\\RateLimitException  — HTTP 429, has $retryAfter\n└── MaxBotApi\\Exceptions\\NetworkException    — network-level errors\n```\n\n---\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprog-time%2Fmax-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprog-time%2Fmax-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprog-time%2Fmax-php-sdk/lists"}