Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
1d79ce65
Commit
1d79ce65
authored
Dec 04, 2015
by
MBoretto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update chat Entities
parent
b9a27949
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
5 deletions
+77
-5
README.md
README.md
+3
-3
Chat.php
src/Entities/Chat.php
+22
-1
Telegram.php
src/Telegram.php
+1
-1
ChatTest.php
tests/Unit/Entities/ChatTest.php
+51
-0
No files found.
README.md
View file @
1d79ce65
...
@@ -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
2
8).
-
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:
...
...
src/Entities/Chat.php
View file @
1d79ce65
...
@@ -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'
)
{
...
...
src/Telegram.php
View file @
1d79ce65
...
@@ -29,7 +29,7 @@ class Telegram
...
@@ -29,7 +29,7 @@ class Telegram
*
*
* @var string
* @var string
*/
*/
protected
$version
=
'0.2
0.2
'
;
protected
$version
=
'0.2
3.0
'
;
/**
/**
* Telegram API key
* Telegram API key
...
...
tests/Unit/Entities/ChatTest.php
0 → 100644
View file @
1d79ce65
<?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
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment