Commit 1d79ce65 authored by MBoretto's avatar MBoretto

Update chat Entities

parent b9a27949
...@@ -21,7 +21,7 @@ Bot aims to provide a platform where one could simply write a plugin ...@@ -21,7 +21,7 @@ Bot aims to provide a platform where one could simply write a plugin
and have interactions in a matter of minutes. and have interactions in a matter of minutes.
The Bot can: The Bot can:
- retrive update with webhook and getUpdate methods. - retrive update with webhook and getUpdate methods.
- supports all types and methods according to Telegram API (2015 October 8). - supports all types and methods according to Telegram API (2015 October 28).
- handle commands in chat with other bots. - handle commands in chat with other bots.
It is ready for the channels support. It is ready for the channels support.
...@@ -303,8 +303,8 @@ Inside *examples/Commands/* there are some sample that show how to use types. ...@@ -303,8 +303,8 @@ Inside *examples/Commands/* there are some sample that show how to use types.
### Admin Commands ### Admin Commands
Enabling this feature, the admin bot can perform some super user command like: Enabling this feature, the admin bot can perform some super user command like:
- Send message to all chats - Send message to all chats */sendtoall*
- List all the chats started with the bot (new!) - List all the chats started with the bot */chats*
You can specify one or more admin with this option: You can specify one or more admin with this option:
......
...@@ -30,7 +30,19 @@ class Chat extends Entity ...@@ -30,7 +30,19 @@ class Chat extends Entity
throw new TelegramException('id is empty!'); throw new TelegramException('id is empty!');
} }
$this->type = isset($data['type']) ? $data['type'] : null; //$this->type = isset($data['type']) ? $data['type'] : null;
if ( isset($data['type']) ) {
$this->type = $data['type'];
} else {
if ($this->isPrivateChat()) {
$this->type = 'private';
} elseif ($this->isGroupChat()) {
$this->type = 'group';
} else {
$this->type = null;
}
}
$this->title = isset($data['title']) ? $data['title'] : null; $this->title = isset($data['title']) ? $data['title'] : null;
$this->first_name = isset($data['first_name']) ? $data['first_name'] : null; $this->first_name = isset($data['first_name']) ? $data['first_name'] : null;
...@@ -56,6 +68,15 @@ class Chat extends Entity ...@@ -56,6 +68,15 @@ class Chat extends Entity
} }
} }
public function isSuperGroup()
{
if ($this->type == 'supergroup') {
return true;
} else {
return false;
}
}
public function isChannel() public function isChannel()
{ {
if ($this->type == 'channel') { if ($this->type == 'channel') {
......
...@@ -29,7 +29,7 @@ class Telegram ...@@ -29,7 +29,7 @@ class Telegram
* *
* @var string * @var string
*/ */
protected $version = '0.20.2'; protected $version = '0.23.0';
/** /**
* Telegram API key * Telegram API key
......
<?php
/*
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\Unit;
use \Longman\TelegramBot\Entities\Chat;
/**
* @package TelegramTest
* @author Avtandil Kikabidze <akalongman@gmail.com>
* @copyright Avtandil Kikabidze <akalongman@gmail.com>
* @license http://opensource.org/licenses/mit-license.php The MIT License (MIT)
* @link http://www.github.com/akalongman/php-telegram-bot
*/
class ChatTest extends TestCase
{
/**
* @var \Longman\TelegramBot\Telegram
*/
private $chat;
/**
* setUp
*/
protected function setUp()
{
}
/**
* @test
*/
public function testChatType()
{
$this->chat = new Chat(json_decode('{"id":123,"title":null,"first_name":"john","last_name":null,"username":"null"}',true));
$this->assertEquals('private', $this->chat->getType());
$this->chat = new Chat(json_decode('{"id":-123,"title":"ChatTitle","first_name":null,"last_name":null,"username":"null"}',true));
$this->assertEquals('group', $this->chat->getType());
$this->chat = new Chat(json_decode('{"id":-123,"type":"channel","title":"ChatTitle","first_name":null,"last_name":null,"username":"null"}',true));
$this->assertEquals('channel', $this->chat->getType());
}
}
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