Commit 02c121f2 authored by MBoretto's avatar MBoretto

All types implemented and stored

parent ada86a45
...@@ -124,7 +124,7 @@ The bot can handle updates with **webhook** or **getUpdate** method: ...@@ -124,7 +124,7 @@ The bot can handle updates with **webhook** or **getUpdate** method:
## Webhook installation ## Webhook installation
You need server with https and composer support. You need server with https and composer support.
You must set a [WebHook](https://core.telegram.org/bots/api#setwebhook) You must set a [WebHook](https://core.telegram.org/bots/api#setwebhook).
Create *set.php* (just edit *example-set.php*) and put into it: Create *set.php* (just edit *example-set.php*) and put into it:
```php ```php
<?php <?php
...@@ -145,14 +145,12 @@ try { ...@@ -145,14 +145,12 @@ try {
} catch (Longman\TelegramBot\Exception\TelegramException $e) { } catch (Longman\TelegramBot\Exception\TelegramException $e) {
echo $e; echo $e;
} }
``` ```
And open your *set.php* via browser. And open your *set.php* via browser.
After create *hook.php* (just edit *example-hook.php*) and put: After, create *hook.php* (or just edit *example-hook.php*) and put:
```php ```php
<?php <?php
$loader = require __DIR__.'/vendor/autoload.php'; $loader = require __DIR__.'/vendor/autoload.php';
...@@ -171,11 +169,10 @@ try { ...@@ -171,11 +169,10 @@ try {
// echo $e; // echo $e;
} }
``` ```
## getUpdate installation NEW! ## getUpdate installation
You need the database Mysql active. You need the database Mysql active.
Create *getUpdateCLI.php* (just edit *example-getUpdateCLI.php*) and Create *getUpdateCLI.php* (just edit *example-getUpdateCLI.php*) and put into it:
put into it:
```php ```php
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
...@@ -223,6 +220,8 @@ You can set a custom prefix to all the tables while you are enabling Mysql: ...@@ -223,6 +220,8 @@ You can set a custom prefix to all the tables while you are enabling Mysql:
```php ```php
$telegram->enableMySQL($credentials, $BOT_NAME.'_'); $telegram->enableMySQL($credentials, $BOT_NAME.'_');
``` ```
### Types New!
All types implemented (except InputFile) according to Telegram API (2015 September 18).
### Commands ### Commands
The bot is able to recognise commands in chat with multiple bot( The bot is able to recognise commands in chat with multiple bot(
...@@ -241,16 +240,15 @@ Favourite colour? **/black, /red** ...@@ -241,16 +240,15 @@ Favourite colour? **/black, /red**
Favourite number? **/1, /134** Favourite number? **/1, /134**
Maybe you would like to develop your own commands. A good practice is Maybe you would like to develop your own commands. A good practice is
to store them outside vendor/. This can be done adding the method: to store them outside *vendor/*. This can be done adding the method:
```php ```php
$COMMANDS_FOLDER = __DIR__.'/Commands/'; $COMMANDS_FOLDER = __DIR__.'/Commands/';
$telegram->addCommandsPath($COMMANDS_FOLDER); $telegram->addCommandsPath($COMMANDS_FOLDER);
``` ```
### Admin Commands (new!) ### Admin Commands
Enabling this feature, the admin bot can perform some super user Enabling this feature, the admin bot can perform some super user command like send message to all.
command like send message to all.
You can specify one or more admin with this option: You can specify one or more admin with this option:
```php ```php
...@@ -286,12 +284,13 @@ print_r($results); ...@@ -286,12 +284,13 @@ print_r($results);
``` ```
### Logging ### Logging
Thrown Exception are stored in TelegramException.log file.
You can also log incoming messages on a text file, set this option with the methods: You can also log incoming messages on a text file, set this option with the methods:
```php ```php
$telegram->setLogRequests(true); $telegram->setLogRequests(true);
$telegram->setLogPath($BOT_NAME.'.log'); $telegram->setLogPath($BOT_NAME.'.log');
``` ```
Thrown Exception are stored in TelegramException.log file.
----- -----
This code is available on This code is available on
......
This diff is collapsed.
...@@ -29,10 +29,9 @@ class Document extends Entity ...@@ -29,10 +29,9 @@ class Document extends Entity
} }
$this->thumb = isset($data['thumb']) ? $data['thumb'] : null; $this->thumb = isset($data['thumb']) ? $data['thumb'] : null;
if (empty($this->file_id)) { if (!empty($this->thumb)) {
throw new TelegramException('thumb is empty!'); $this->thumb = new PhotoSize($this->thumb);
} }
$this->thumb = new PhotoSize($this->thumb);
$this->file_name = isset($data['file_name']) ? $data['file_name'] : null; $this->file_name = isset($data['file_name']) ? $data['file_name'] : null;
$this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null; $this->mime_type = isset($data['mime_type']) ? $data['mime_type'] : null;
......
...@@ -122,9 +122,9 @@ class Message extends Entity ...@@ -122,9 +122,9 @@ class Message extends Entity
$this->photo = isset($data['photo']) ? $data['photo'] : null; //array of photosize $this->photo = isset($data['photo']) ? $data['photo'] : null; //array of photosize
if (!empty($this->photo)) { if (!empty($this->photo)) {
foreach($this->photo as $photo){ foreach ($this->photo as $photo) {
if(!empty($photo)) { if (!empty($photo)) {
$photos[] = new PhotoSize($photo); $photos[] = new PhotoSize($photo);
} }
} }
$this->photo = $photos; $this->photo = $photos;
......
...@@ -3,24 +3,24 @@ CREATE TABLE `messages` ( ...@@ -3,24 +3,24 @@ CREATE TABLE `messages` (
`message_id` bigint COMMENT 'Unique message identifier', `message_id` bigint COMMENT 'Unique message identifier',
`user_id` bigint COMMENT 'User identifier', `user_id` bigint COMMENT 'User identifier',
`date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date the message was sent in timestamp format', `date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Date the message was sent in timestamp format',
`chat_id` bigint NOT NULL DEFAULT '0' COMMENT 'User or GroupChat object. Conversation the message belongs to — user in case of a private message, GroupChat in case of a group', `chat_id` bigint NOT NULL DEFAULT '0' COMMENT 'Chat identifier.',
`forward_from` VARCHAR(511) DEFAULT '' COMMENT 'User object. For forwarded messages, sender of the original message', `forward_from` bigint NOT NULL DEFAULT '0' COMMENT 'User id. For forwarded messages, sender of the original message',
`forward_date` int(511) UNSIGNED DEFAULT 0 COMMENT 'For forwarded messages, date the original message was sent in Unix time', `forward_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'For forwarded messages, date the original message was sent in Unix time',
`reply_to_message` LONGTEXT COMMENT 'Message object. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.', `reply_to_message` LONGTEXT COMMENT 'Message object. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.',
`text` LONGTEXT COMMENT 'For text messages, the actual UTF-8 text of the message', `text` LONGTEXT COMMENT 'For text messages, the actual UTF-8 text of the message',
`audio` VARCHAR(511) DEFAULT '' COMMENT 'Audio object. Message is an audio file, information about the file', `audio` TEXT DEFAULT '' COMMENT 'Audio object. Message is an audio file, information about the file',
`document` VARCHAR(511) DEFAULT '' COMMENT 'Document object. Message is a general file, information about the file', `document` TEXT DEFAULT '' COMMENT 'Document object. Message is a general file, information about the file',
`photo` VARCHAR(511) DEFAULT '' COMMENT 'Array of PhotoSize objects. Message is a photo, available sizes of the photo', `photo` TEXT DEFAULT '' COMMENT 'Array of PhotoSize objects. Message is a photo, available sizes of the photo',
`sticker` VARCHAR(511) DEFAULT '' COMMENT 'Sticker object. Message is a sticker, information about the sticker', `sticker` TEXT DEFAULT '' COMMENT 'Sticker object. Message is a sticker, information about the sticker',
`video` VARCHAR(511) DEFAULT '' COMMENT 'Video object. Message is a video, information about the video', `video` TEXT DEFAULT '' COMMENT 'Video object. Message is a video, information about the video',
`voice` VARCHAR(511) DEFAULT '' COMMENT 'Voice Object. Message is a Voice, information about the Voice', `voice` TEXT DEFAULT '' COMMENT 'Voice Object. Message is a Voice, information about the Voice',
`caption` LONGTEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption', `caption` LONGTEXT COMMENT 'For message with caption, the actual UTF-8 text of the caption',
`contact` VARCHAR(511) DEFAULT '' COMMENT 'Contact object. Message is a shared contact, information about the contact', `contact` TEXT DEFAULT '' COMMENT 'Contact object. Message is a shared contact, information about the contact',
`location` VARCHAR(511) DEFAULT '' COMMENT 'Location object. Message is a shared location, information about the location', `location` TEXT DEFAULT '' COMMENT 'Location object. Message is a shared location, information about the location',
`new_chat_participant` VARCHAR(511) COMMENT 'User object. A new member was added to the group, information about them (this member may be bot itself)', `new_chat_participant` bigint NOT NULL DEFAULT '0' COMMENT 'User id. A new member was added to the group, information about them (this member may be bot itself)',
`left_chat_participant` VARCHAR(511) COMMENT 'User object. A member was removed from the group, information about them (this member may be bot itself)', `left_chat_participant` bigint NOT NULL DEFAULT '0' COMMENT 'User id. A member was removed from the group, information about them (this member may be bot itself)',
`new_chat_title` VARCHAR(511) DEFAULT '' COMMENT 'A group title was changed to this value', `new_chat_title` CHAR(255) DEFAULT '' COMMENT 'A group title was changed to this value',
`new_chat_photo` VARCHAR(511) DEFAULT '' COMMENT 'Array of PhotoSize objects. A group photo was change to this value', `new_chat_photo` TEXT DEFAULT '' COMMENT 'Array of PhotoSize objects. A group photo was change to this value',
`delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group photo was deleted', `delete_chat_photo` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group photo was deleted',
`group_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group has been created', `group_chat_created` tinyint(1) DEFAULT 0 COMMENT 'Informs that the group has been created',
PRIMARY KEY (`update_id`), PRIMARY KEY (`update_id`),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment