This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
2,869 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
### JetBrains template | ||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm | ||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 | ||
|
||
# User-specific stuff: | ||
.idea/ | ||
|
||
## File-based project format: | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
/out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
# JIRA plugin | ||
atlassian-ide-plugin.xml | ||
|
||
#other | ||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "lukasss93/telegrambot-php", | ||
"description": "Framework for Telegram Bot API", | ||
"license": "MIT", | ||
"type": "project", | ||
"version": "1.0.0", | ||
"authors": [ | ||
{ | ||
"name": "Luca Patera", | ||
"email": "[email protected]", | ||
"homepage": "http://www.lucapatera.it/" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.3", | ||
"netresearch/jsonmapper": "v1.1.0", | ||
"lukasss93/aurax-php": "1.3.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"TelegramBot\\": "src/", | ||
"TelegramBot\\Types\\": "src/Types/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# TelegramBotPHP | ||
> A very simple PHP [Telegram Bot API](https://core.telegram.org/bots/api) for sending messages. | ||
> Compliant with the December 4, 2016 Telegram Bot API update. | ||
Requirements | ||
--------- | ||
|
||
* PHP 5.3+ | ||
* Curl for PHP must be enabled. | ||
* Telegram API Key, you can get one simply with [@BotFather](https://core.telegram.org/bots#botfather) with simple commands right after creating your bot. | ||
|
||
For the WebHook: | ||
* An SSL certificate (Telegram API requires this). You can use [Cloudflare's Free Flexible SSL](https://www.cloudflare.com/ssl) which crypts the web traffic from end user to their proxies if you're using CloudFlare DNS. | ||
Since the August 29 update you can use a self-signed ssl certificate. | ||
|
||
For the GetUpdates: | ||
* Some way to execute the script in order to serve messages (for example cronjob) | ||
|
||
Installation | ||
--------- | ||
|
||
* ####Manual | ||
Copy **src** folder in your project, rename it and include all classes in your new bot script. | ||
```php | ||
//add a script to include the entire folder first! | ||
$telegram = new TelegramBot($token); | ||
``` | ||
* ####Composer | ||
|
||
`composer require lukasss93/telegrambot` | ||
|
||
Configuration (WebHook) | ||
--------- | ||
|
||
Navigate to | ||
https://api.telegram.org/bot(TOKEN)/setWebhook?url=https://yoursite.com/your_update.php | ||
Or use the Telegram class setWebhook method. | ||
|
||
Informations | ||
--------- | ||
|
||
This simple framework is object-based, all methods return a Telegram Object contained in TelegramBot/Types namespace. | ||
|
||
Examples | ||
--------- | ||
|
||
```php | ||
use TelegramBot\TelegramBot; | ||
|
||
$telegram = new TelegramBot($token); | ||
$input=$telegram->getWebhookUpdate(); | ||
$this->telegram->sendMessage([ | ||
'chat_id' => $input->message->chat->id, | ||
'text' => 'Hello world!' | ||
]); | ||
``` | ||
|
||
If you want to get some specific parameter from the Telegram webhook, simply call parameter name in the object: | ||
```php | ||
$telegram = new TelegramBot($token); | ||
$input=$telegram->getWebhookUpdate(); | ||
$text=$input->message->text | ||
``` | ||
|
||
To upload a Photo or some other files, you need to load it with CurlFile: | ||
```php | ||
// Load a local file to upload. If is already on Telegram's Servers just pass the resource id | ||
$img = curl_file_create('test.png','image/png'); | ||
$telegram->sendPhoto([ | ||
'chat_id' => $chat_id, | ||
'photo' => $img | ||
]); | ||
``` | ||
|
||
To download a file on the Telegram's servers | ||
```php | ||
$file = $telegram->getFile($file_id); | ||
$telegram->downloadFile($file["file_path"], "./my_downloaded_file_on_local_server.png"); | ||
``` | ||
|
||
Build keyboard parameters | ||
------------ | ||
```php | ||
buildKeyBoard(array $options, $onetime=true, $resize=true, $selective=true) | ||
``` | ||
Send a custom keyboard. $option is an array of array KeyboardButton. | ||
Check [ReplyKeyBoardMarkUp](https://core.telegram.org/bots/api#replykeyboardmarkup) for more info. | ||
|
||
```php | ||
buildInlineKeyBoard(array $inline_keyboard) | ||
``` | ||
Send a custom keyboard. $inline_keyboard is an array of array InlineKeyboardButton. | ||
Check [InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) for more info. | ||
|
||
```php | ||
buildInlineKeyBoardButton($text, $url, $callback_data, $switch_inline_query) | ||
``` | ||
Create an InlineKeyboardButton. | ||
Check [InlineKeyBoardButton](https://core.telegram.org/bots/api#inlinekeyboardbutton) for more info. | ||
|
||
```php | ||
buildKeyBoardButton($text, $url, $request_contact, $request_location) | ||
``` | ||
Create a KeyboardButton. | ||
Check [KeyBoardButton](https://core.telegram.org/bots/api#keyboardbutton) for more info. | ||
|
||
|
||
```php | ||
buildKeyBoardHide($selective=true) | ||
``` | ||
Hide a custom keyboard. | ||
Check [ReplyKeyBoarHide](https://core.telegram.org/bots/api#replykeyboardhide) for more info. | ||
|
||
```php | ||
buildForceReply($selective=true) | ||
``` | ||
Show a Reply interface to the user. | ||
Check [ForceReply](https://core.telegram.org/bots/api#forcereply) for more info. | ||
|
||
Emoticons | ||
------------ | ||
For a list of emoticons to use in your bot messages, please refer to the column Bytes of this table: | ||
http://apps.timwhitlock.info/emoji/tables/unicode | ||
|
||
Contact me | ||
------------ | ||
You can contact me [via Telegram](https://telegram.me/Lukasss93) but if you have an issue please [open](https://github.com/Eleirbag89/TelegramBotPHP/issues) one. |
Oops, something went wrong.