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
55c2e1a7
Unverified
Commit
55c2e1a7
authored
Jul 14, 2018
by
Armando Lüscher
Committed by
GitHub
Jul 14, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into 726-games
parents
d15384ec
586d14cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
3 deletions
+105
-3
ServerResponse.php
src/Entities/ServerResponse.php
+1
-0
InvalidBotTokenException.php
src/Exception/InvalidBotTokenException.php
+25
-0
Request.php
src/Request.php
+12
-3
ServerResponseTest.php
tests/unit/Entities/ServerResponseTest.php
+67
-0
No files found.
src/Entities/ServerResponse.php
View file @
55c2e1a7
...
...
@@ -112,6 +112,7 @@ class ServerResponse extends Entity
$result_object_types
=
[
'total_count'
=>
'UserProfilePhotos'
,
//Response from getUserProfilePhotos
'stickers'
=>
'StickerSet'
,
//Response from getStickerSet
'file_id'
=>
'File'
,
//Response from getFile
'title'
=>
'Chat'
,
//Response from getChat
'username'
=>
'User'
,
//Response from getMe
...
...
src/Exception/InvalidBotTokenException.php
0 → 100644
View file @
55c2e1a7
<?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
Longman\TelegramBot\Exception
;
/**
* Thrown when bot token is invalid
*/
class
InvalidBotTokenException
extends
TelegramException
{
/**
* InvalidBotTokenException constructor
*/
public
function
__construct
()
{
parent
::
__construct
(
"Invalid bot token!"
);
}
}
src/Request.php
View file @
55c2e1a7
...
...
@@ -14,6 +14,7 @@ use GuzzleHttp\Client;
use
GuzzleHttp\Exception\RequestException
;
use
Longman\TelegramBot\Entities\File
;
use
Longman\TelegramBot\Entities\ServerResponse
;
use
Longman\TelegramBot\Exception\InvalidBotTokenException
;
use
Longman\TelegramBot\Exception\TelegramException
;
/**
...
...
@@ -463,13 +464,21 @@ class Request
self
::
limitTelegramRequests
(
$action
,
$data
);
$response
=
json_decode
(
self
::
execute
(
$action
,
$data
),
true
);
$raw_response
=
self
::
execute
(
$action
,
$data
);
$response
=
json_decode
(
$raw_response
,
true
);
if
(
null
===
$response
)
{
throw
new
TelegramException
(
'Telegram returned an invalid response! Please review your bot name and API key.'
);
TelegramLog
::
debug
(
$raw_response
);
throw
new
TelegramException
(
'Telegram returned an invalid response!'
);
}
return
new
ServerResponse
(
$response
,
$bot_username
);
$response
=
new
ServerResponse
(
$response
,
$bot_username
);
if
(
!
$response
->
isOk
()
&&
$response
->
getErrorCode
()
===
401
&&
$response
->
getDescription
()
===
'Unauthorized'
)
{
throw
new
InvalidBotTokenException
();
}
return
$response
;
}
/**
...
...
tests/unit/Entities/ServerResponseTest.php
View file @
55c2e1a7
...
...
@@ -298,4 +298,71 @@ class ServerResponseTest extends TestCase
//... they are not finished...
}
public
function
getStickerSet
()
{
return
'{
"ok":true,
"result":{
"name":"stickerset_name",
"title":"Some name",
"contains_masks":false,
"stickers":[
{
"width":512,
"height":324,
"emoji":"\ud83d\ude33",
"set_name":"stickerset_name",
"thumb":{"file_id":"AAQEABOKTFsZAASfA4t3pp1_VlH1AAIC","file_size":3120,"width":128,"height":81},
"file_id":"CAADBAADzAIAAph_7gOATSb9ehxv5QI",
"file_size":14246
},
{
"width":419,
"height":512,
"emoji":"\u2764",
"set_name":"stickerset_name",
"thumb":{"file_id":"AAQEABMj8qoZAASePUHuDSJ2uGIKAAIC","file_size":3500,"width":105,"height":128},
"file_id":"CAADBAADzQIAAph_7gNPFguft4qtjAI",
"file_size":17814
},
{
"width":512,
"height":276,
"emoji":"\ud83d\ude36",
"set_name":"stickerset_name",
"thumb":{"file_id":"AAQEABMiaWcZAATNUEPkYkd0Fh2JBAABAg","file_size":2642,"file_path":"thumbnails\/file_8.jpg","width":128,"height":69},
"file_id":"CAADBAADzwIAAph_7gOClxA3gK5wqAI",
"file_size":12258
},
{
"width":512,
"height":327,
"emoji":"\ud83d\udcbb",
"set_name":"stickerset_name",
"thumb":{"file_id":"AAQEABPC3d8ZAAQUJJnFB1VfII2RAAIC","file_size":3824,"file_path":"thumbnails\/file_10.jpg","width":128,"height":82},
"file_id":"CAADBAAD0QIAAph_7gO-vBJGkTeWqwI",
"file_size":18282
}
]
}
}'
;
}
public
function
testGetStickerSet
()
{
$result
=
$this
->
getStickerSet
();
$server
=
new
ServerResponse
(
json_decode
(
$result
,
true
),
'testbot'
);
$server_result
=
$server
->
getResult
();
self
::
assertInstanceOf
(
'\Longman\TelegramBot\Entities\StickerSet'
,
$server_result
);
self
::
assertEquals
(
'stickerset_name'
,
$server_result
->
getName
());
self
::
assertEquals
(
'Some name'
,
$server_result
->
getTitle
());
self
::
assertFalse
(
$server_result
->
getContainsMasks
());
$stickers
=
$server_result
->
getStickers
();
self
::
assertCount
(
4
,
$stickers
);
self
::
assertInstanceOf
(
'\Longman\TelegramBot\Entities\Sticker'
,
$stickers
[
0
]);
}
}
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