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
15afa620
Commit
15afa620
authored
May 23, 2016
by
Jack'lul
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3 from MBoretto/conflict
Conflict
parents
09d4337e
307c4cea
Changes
44
Hide whitespace changes
Inline
Side-by-side
Showing
44 changed files
with
863 additions
and
188 deletions
+863
-188
CREDITS
CREDITS
+5
-0
README.md
README.md
+22
-0
InlinekeyboardCommand.php
examples/Commands/InlinekeyboardCommand.php
+11
-96
getUpdatesCLI.php
examples/getUpdatesCLI.php
+3
-0
hook.php
examples/hook.php
+3
-0
Botan.php
src/Botan.php
+175
-0
BotanDB.php
src/BotanDB.php
+101
-0
SendtoallCommand.php
src/Commands/AdminCommands/SendtoallCommand.php
+1
-3
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+3
-3
InlinequeryCommand.php
src/Commands/SystemCommands/InlinequeryCommand.php
+4
-3
Audio.php
src/Entities/Audio.php
+2
-3
Chat.php
src/Entities/Chat.php
+0
-7
ChosenInlineResult.php
src/Entities/ChosenInlineResult.php
+0
-2
Contact.php
src/Entities/Contact.php
+0
-2
Document.php
src/Entities/Document.php
+4
-6
Entity.php
src/Entities/Entity.php
+3
-2
File.php
src/Entities/File.php
+2
-4
InlineKeyboardButton.php
src/Entities/InlineKeyboardButton.php
+4
-5
InlineKeyboardMarkup.php
src/Entities/InlineKeyboardMarkup.php
+0
-3
InlineQuery.php
src/Entities/InlineQuery.php
+4
-2
InlineQueryResult.php
src/Entities/InlineQueryResult.php
+11
-0
InlineQueryResultArticle.php
src/Entities/InlineQueryResultArticle.php
+0
-1
InlineQueryResultCachedAudio.php
src/Entities/InlineQueryResultCachedAudio.php
+35
-0
InlineQueryResultCachedDocument.php
src/Entities/InlineQueryResultCachedDocument.php
+61
-0
InlineQueryResultCachedGif.php
src/Entities/InlineQueryResultCachedGif.php
+51
-0
InlineQueryResultCachedMpeg4Gif.php
src/Entities/InlineQueryResultCachedMpeg4Gif.php
+50
-0
InlineQueryResultCachedPhoto.php
src/Entities/InlineQueryResultCachedPhoto.php
+57
-0
InlineQueryResultCachedSticker.php
src/Entities/InlineQueryResultCachedSticker.php
+35
-0
InlineQueryResultCachedVideo.php
src/Entities/InlineQueryResultCachedVideo.php
+61
-0
InlineQueryResultCachedVoice.php
src/Entities/InlineQueryResultCachedVoice.php
+61
-0
InlineQueryResultGif.php
src/Entities/InlineQueryResultGif.php
+5
-2
InlineQueryResultMpeg4Gif.php
src/Entities/InlineQueryResultMpeg4Gif.php
+5
-2
InlineQueryResultPhoto.php
src/Entities/InlineQueryResultPhoto.php
+6
-2
InlineQueryResultVideo.php
src/Entities/InlineQueryResultVideo.php
+8
-1
InputContactMessageContent.php
src/Entities/InputContactMessageContent.php
+3
-5
InputLocationMessageContent.php
src/Entities/InputLocationMessageContent.php
+2
-4
InputTextMessageContent.php
src/Entities/InputTextMessageContent.php
+3
-5
InputVenueMessageContent.php
src/Entities/InputVenueMessageContent.php
+5
-7
Message.php
src/Entities/Message.php
+0
-1
MessageEntity.php
src/Entities/MessageEntity.php
+6
-3
ReplyKeyboardMarkup.php
src/Entities/ReplyKeyboardMarkup.php
+0
-3
Request.php
src/Request.php
+2
-1
Telegram.php
src/Telegram.php
+32
-0
structure.sql
structure.sql
+17
-10
No files found.
CREDITS
View file @
15afa620
...
...
@@ -21,3 +21,8 @@ N: Armando Lüscher
E: armando@noplanman.ch
W: http://noplanman.ch
D: Maintainer and Collaborator
N: Jack'lul (alias)
E: jacklul@jacklul.com
W: http://jacklul.com
D: Maintainer and Collaborator
README.md
View file @
15afa620
...
...
@@ -34,6 +34,7 @@ A Telegram Bot based on the official [Telegram Bot API](https://core.telegram.or
-
[
Utils
](
#utils
)
-
[
MySQL storage (Recommended)
](
#mysql-storage-recommended
)
-
[
Channels Support
](
#channels-support
)
-
[
Botan.io integration (Optional)
](
#botanio-integration-optional
)
-
[
Commands
](
#commands
)
-
[
Predefined Commands
](
#predefined-commands
)
-
[
Custom Commands
](
#custom-commands
)
...
...
@@ -401,6 +402,27 @@ $telegram->enableExternalMysql($external_pdo_connection)
All methods implemented can be used to manage channels.
With
[
admin commands
](
#admin-commands
)
you can manage your channels directly with your bot private chat.
### Botan.io integration (Optional)
You can enable the integration using this line:
```
php
$telegram
->
enableBotan
(
'your_token'
);
```
Replace
```'your_token'```
with your Botan.io token, check
[
this page
](
https://github.com/botanio/sdk#creating-an-account
)
to see how to obtain one.
The following actions will be tracked:
-
Commands (shown as
`Command (/command_name)`
in the stats
-
Inline Queries, Chosen Inline Results and Callback Queries
-
Messages sent to the bot (or replies in groups)
In order to use the URL shortener you must include the class
```use Longman\TelegramBot\Botan;```
and call it like this:
```
Botan::shortenUrl('https://github.com/akalongman/php-telegram-bot', $user_id);```
Shortened URLs are cached in the database (if MySQL storage is enabled).
### Commands
#### Predefined Commands
...
...
examples/Commands/InlinekeyboardCommand.php
View file @
15afa620
...
...
@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use
Longman\TelegramBot\Commands\UserCommand
;
use
Longman\TelegramBot\Request
;
use
Longman\TelegramBot\Entities\InlineKeyboardMarkup
;
use
Longman\TelegramBot\Entities\InlineKeyboardButton
;
/**
* User "/inlinekeyboard" command
...
...
@@ -22,8 +23,8 @@ class InlinekeyboardCommand extends UserCommand
/**#@+
* {@inheritdoc}
*/
protected
$name
=
'
i
nlinekeyboard'
;
protected
$description
=
'Show
a custom inline keybord with reply markup
'
;
protected
$name
=
'
I
nlinekeyboard'
;
protected
$description
=
'Show
inline keyboard
'
;
protected
$usage
=
'/inlinekeyboard'
;
protected
$version
=
'0.0.1'
;
/**#@-*/
...
...
@@ -34,104 +35,18 @@ class InlinekeyboardCommand extends UserCommand
public
function
execute
()
{
$message
=
$this
->
getMessage
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$text
=
$message
->
getText
(
true
);
$data
=
[];
$data
[
'chat_id'
]
=
$chat_id
;
$data
[
'text'
]
=
'Press a Button:'
;
//Keyboard examples
$inline_keyboards
=
[];
//0
$inline_keyboard
[]
=
[
[
'text'
=>
'<'
,
'callback_data'
=>
'go_left'
],
[
'text'
=>
'^'
,
'callback_data'
=>
'go_up'
],
[
'text'
=>
'>'
,
'callback_data'
=>
'go_right'
]
];
$inline_keyboards
[]
=
$inline_keyboard
;
unset
(
$inline_keyboard
);
//1
$inline_keyboard
[]
=
[
[
'text'
=>
'open google.com'
,
'url'
=>
'google.com'
],
[
'text'
=>
'open youtube.com'
,
'url'
=>
'youtube.com'
]
];
$inline_keyboards
[]
=
$inline_keyboard
;
unset
(
$inline_keyboard
);
//2
$inline_keyboard
[]
=
[
[
'text'
=>
'search \'test\' inline'
,
'switch_inline_query'
=>
'test'
],
[
'text'
=>
'search \'cats\' inline'
,
'switch_inline_query'
=>
'cats'
]
$inline_keyboard
=
[
new
InlineKeyboardButton
([
'text'
=>
'inline'
,
'switch_inline_query'
=>
'true'
]),
new
InlineKeyboardButton
([
'text'
=>
'callback'
,
'callback_data'
=>
'identifier'
]),
new
InlineKeyboardButton
([
'text'
=>
'open url'
,
'url'
=>
'https://github.com/akalongman/php-telegram-bot'
]),
];
$inline_keyboard
[]
=
[
[
'text'
=>
'search \'earth\' inline'
,
'switch_inline_query'
=>
'earth'
],
$data
=
[
'chat_id'
=>
$message
->
getChat
()
->
getId
(),
'text'
=>
'inline keyboard'
,
'reply_markup'
=>
new
InlineKeyboardMarkup
([
'inline_keyboard'
=>
[
$inline_keyboard
]]),
];
$inline_keyboards
[]
=
$inline_keyboard
;
unset
(
$inline_keyboard
);
//3
$inline_keyboard
[]
=
[
[
'text'
=>
'open url'
,
'url'
=>
'https://github.com/akalongman/php-telegram-bot'
]
];
$inline_keyboard
[]
=
[
[
'text'
=>
'switch to inline'
,
'switch_inline_query'
=>
'thumb up'
]
];
$inline_keyboard
[]
=
[
[
'text'
=>
'send callback query'
,
'callback_data'
=>
'thumb up'
],
[
'text'
=>
'send callback query (no alert)'
,
'callback_data'
=>
'thumb down'
]
];
$inline_keyboards
[]
=
$inline_keyboard
;
unset
(
$inline_keyboard
);
$data
[
'reply_markup'
]
=
new
InlineKeyboardMarkup
(
[
'inline_keyboard'
=>
$inline_keyboards
[
3
],
]
);
return
Request
::
sendMessage
(
$data
);
}
}
examples/getUpdatesCLI.php
View file @
15afa620
...
...
@@ -50,6 +50,9 @@ try {
//$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
//// Botan.io integration
//$telegram->enableBotan('your_token');
// Handle telegram getUpdate request
$ServerResponse
=
$telegram
->
handleGetUpdates
();
...
...
examples/hook.php
View file @
15afa620
...
...
@@ -48,6 +48,9 @@ try {
//$telegram->setDownloadPath('../Download');
//$telegram->setUploadPath('../Upload');
//// Botan.io integration
//$telegram->enableBotan('your_token');
// Handle telegram webhook request
$telegram
->
handle
();
}
catch
(
Longman\TelegramBot\Exception\TelegramException
$e
)
{
...
...
src/Botan.php
0 → 100644
View file @
15afa620
<?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
;
use
Longman\TelegramBot\Exception\TelegramException
;
/**
* Class Botan
*
* Integration with http://botan.io statistics service for Telegram bots
*/
class
Botan
{
/**
* @var string Tracker request url
*/
protected
static
$track_url
=
'https://api.botan.io/track?token=#TOKEN&uid=#UID&name=#NAME'
;
/**
* @var string Url Shortener request url
*/
protected
static
$shortener_url
=
'https://api.botan.io/s/?token=#TOKEN&user_ids=#UID&url=#URL'
;
/**
* @var string Yandex AppMetrica application key
*/
protected
static
$token
=
''
;
/**
* Initilize botan
*/
public
static
function
initializeBotan
(
$token
)
{
if
(
empty
(
$token
)
||
!
is_string
(
$token
))
{
throw
new
TelegramException
(
'Botan token should be a string!'
);
}
self
::
$token
=
$token
;
BotanDB
::
initializeBotanDb
();
}
/**
* Track function
*
* @todo Advanced integration: https://github.com/botanio/sdk#advanced-integration
*
* @param string $input
* @param string $command
* @return bool|string
*/
public
static
function
track
(
$input
,
$command
=
''
)
{
if
(
empty
(
self
::
$token
))
{
return
false
;
}
if
(
empty
(
$input
))
{
throw
new
TelegramException
(
'Input is empty!'
);
}
$obj
=
json_decode
(
$input
,
true
);
if
(
isset
(
$obj
[
'message'
]))
{
$data
=
$obj
[
'message'
];
if
((
isset
(
$obj
[
'message'
][
'entities'
])
&&
$obj
[
'message'
][
'entities'
][
0
][
'type'
]
==
'bot_command'
&&
$obj
[
'message'
][
'entities'
][
0
][
'offset'
]
==
0
)
||
substr
(
$obj
[
'message'
][
'text'
],
0
,
1
)
==
'/'
)
{
if
(
strtolower
(
$command
)
==
'generic'
)
{
$command
=
'Generic'
;
}
elseif
(
strtolower
(
$command
)
==
'genericmessage'
)
{
$command
=
'Generic Message'
;
}
else
{
$command
=
'/'
.
strtolower
(
$command
);
}
$event_name
=
'Command ('
.
$command
.
')'
;
}
else
{
$event_name
=
'Message'
;
}
}
elseif
(
isset
(
$obj
[
'inline_query'
]))
{
$data
=
$obj
[
'inline_query'
];
$event_name
=
'Inline Query'
;
}
elseif
(
isset
(
$obj
[
'chosen_inline_result'
]))
{
$data
=
$obj
[
'chosen_inline_result'
];
$event_name
=
'Chosen Inline Result'
;
}
elseif
(
isset
(
$obj
[
'callback_query'
]))
{
$data
=
$obj
[
'callback_query'
];
$event_name
=
'Callback Query'
;
}
if
(
empty
(
$event_name
))
{
return
false
;
}
$uid
=
$data
[
'from'
][
'id'
];
$request
=
str_replace
(
[
'#TOKEN'
,
'#UID'
,
'#NAME'
],
[
self
::
$token
,
$uid
,
urlencode
(
$event_name
)],
self
::
$track_url
);
$options
=
[
'http'
=>
[
'header'
=>
'Content-Type: application/json'
,
'method'
=>
'POST'
,
'content'
=>
json_encode
(
$data
),
'ignore_errors'
=>
true
]
];
$context
=
stream_context_create
(
$options
);
$response
=
@
file_get_contents
(
$request
,
false
,
$context
);
$responseData
=
json_decode
(
$response
,
true
);
if
(
$responseData
[
'status'
]
!=
'accepted'
)
{
error_log
(
'Botan.io API replied with error: '
.
$response
);
}
return
$responseData
;
}
/**
* Url Shortener function
*
* @param $url
* @param $user_id
* @return string
*/
public
static
function
shortenUrl
(
$url
,
$user_id
)
{
if
(
empty
(
self
::
$token
))
{
return
$url
;
}
if
(
empty
(
$user_id
))
{
throw
new
TelegramException
(
'User id is empty!'
);
}
$cached
=
BotanDB
::
selectShortUrl
(
$user_id
,
$url
);
if
(
!
empty
(
$cached
[
0
][
'short_url'
]))
{
return
$cached
[
0
][
'short_url'
];
}
$request
=
str_replace
(
[
'#TOKEN'
,
'#UID'
,
'#URL'
],
[
self
::
$token
,
$user_id
,
urlencode
(
$url
)],
self
::
$shortener_url
);
$options
=
[
'http'
=>
[
'ignore_errors'
=>
true
,
'timeout'
=>
3
]
];
$context
=
stream_context_create
(
$options
);
$response
=
@
file_get_contents
(
$request
,
false
,
$context
);
if
(
!
filter_var
(
$response
,
FILTER_VALIDATE_URL
)
===
false
)
{
BotanDB
::
insertShortUrl
(
$user_id
,
$url
,
$response
);
}
else
{
error_log
(
'Botan.io API replied with error: '
.
$response
);
return
$url
;
}
return
$response
;
}
}
src/BotanDB.php
0 → 100644
View file @
15afa620
<?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
;
use
Longman\TelegramBot\DB
;
use
Longman\TelegramBot\Exception\TelegramException
;
/**
* Class BotanDB
*/
class
BotanDB
extends
DB
{
/**
* Initilize botan shortener table
*/
public
static
function
initializeBotanDb
()
{
if
(
!
defined
(
'TB_BOTAN_SHORTENER'
))
{
define
(
'TB_BOTAN_SHORTENER'
,
self
::
$table_prefix
.
'botan_shortener'
);
}
}
/**
* Select cached shortened URL from the database
*
* @param $user_id
* @param $url
* @return bool|string
* @throws TelegramException
*/
public
static
function
selectShortUrl
(
$user_id
,
$url
)
{
if
(
!
self
::
isDbConnected
())
{
return
false
;
}
try
{
$sth
=
self
::
$pdo
->
prepare
(
'SELECT * FROM `'
.
TB_BOTAN_SHORTENER
.
'`
WHERE `user_id` = :user_id AND `url` = :url
'
);
$sth
->
bindParam
(
':user_id'
,
$user_id
,
\PDO
::
PARAM_INT
);
$sth
->
bindParam
(
':url'
,
$url
,
\PDO
::
PARAM_INT
);
$sth
->
execute
();
$results
=
$sth
->
fetchAll
(
\PDO
::
FETCH_ASSOC
);
}
catch
(
\Exception
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
return
$results
;
}
/**
* Insert shortened URL into the database
*
* @param $user_id
* @param $url
* @param $short_url
* @return bool
* @throws TelegramException
*/
public
static
function
insertShortUrl
(
$user_id
,
$url
,
$short_url
)
{
if
(
!
self
::
isDbConnected
())
{
return
false
;
}
try
{
$sth
=
self
::
$pdo
->
prepare
(
'INSERT INTO `'
.
TB_BOTAN_SHORTENER
.
'`
(
`user_id`, `url`, `short_url`, `created_at`
)
VALUES (
:user_id, :url, :short_url, :date
)
'
);
$created_at
=
self
::
getTimestamp
();
$sth
->
bindParam
(
':user_id'
,
$user_id
);
$sth
->
bindParam
(
':url'
,
$url
);
$sth
->
bindParam
(
':short_url'
,
$short_url
);
$sth
->
bindParam
(
':date'
,
$created_at
);
$status
=
$sth
->
execute
();
}
catch
(
\Exception
$e
)
{
throw
new
TelegramException
(
$e
->
getMessage
());
}
return
$status
;
}
}
src/Commands/AdminCommands/SendtoallCommand.php
View file @
15afa620
...
...
@@ -31,8 +31,6 @@ class SendtoallCommand extends AdminCommand
/**
* Execute command
*
* @todo Don't use empty, as a string of '0' is regarded to be empty
*
* @return boolean
*/
public
function
execute
()
...
...
@@ -42,7 +40,7 @@ class SendtoallCommand extends AdminCommand
$chat_id
=
$message
->
getChat
()
->
getId
();
$text
=
$message
->
getText
(
true
);
if
(
empty
(
$text
)
)
{
if
(
$text
===
''
)
{
$text
=
'Write the message to send: /sendtoall <message>'
;
}
else
{
$results
=
Request
::
sendToActiveChats
(
...
...
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
15afa620
...
...
@@ -67,7 +67,7 @@ class SendtochannelCommand extends AdminCommand
switch
(
$state
)
{
case
-
1
:
// getConfig has not been configured asking for channel to administer
if
(
$type
!=
'Message'
||
empty
(
$text
)
)
{
if
(
$type
!=
'Message'
||
$text
===
''
)
{
$this
->
conversation
->
notes
[
'state'
]
=
-
1
;
$this
->
conversation
->
update
();
...
...
@@ -116,7 +116,7 @@ class SendtochannelCommand extends AdminCommand
// no break
case
1
:
insert
:
if
(
$this
->
conversation
->
notes
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
(
$type
==
'Message'
&&
empty
(
$text
)
))
{
if
(
$this
->
conversation
->
notes
[
'last_message_id'
]
==
$message
->
getMessageId
()
||
(
$type
==
'Message'
&&
$text
===
''
))
{
$this
->
conversation
->
notes
[
'state'
]
=
1
;
$this
->
conversation
->
update
();
...
...
@@ -245,7 +245,7 @@ class SendtochannelCommand extends AdminCommand
$data
=
[];
$data
[
'chat_id'
]
=
$chat_id
;
if
(
empty
(
$text
)
)
{
if
(
$text
===
''
)
{
$data
[
'text'
]
=
'Usage: /sendtochannel <text>'
;
}
else
{
$channels
=
(
array
)
$this
->
getConfig
(
'your_channel'
);
...
...
src/Commands/SystemCommands/InlinequeryCommand.php
View file @
15afa620
...
...
@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\SystemCommands;
use
Longman\TelegramBot\Commands\SystemCommand
;
use
Longman\TelegramBot\Entities\InlineQueryResultArticle
;
use
Longman\TelegramBot\Entities\InputTextMessageContent
;
use
Longman\TelegramBot\Request
;
/**
...
...
@@ -39,9 +40,9 @@ class InlinequeryCommand extends SystemCommand
$data
=
[
'inline_query_id'
=>
$inline_query
->
getId
()];
$articles
=
[
[
'id'
=>
'001'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
[
'message_text'
=>
$query
]
],
[
'id'
=>
'002'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
[
'message_text'
=>
$query
]
],
[
'id'
=>
'003'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
[
'message_text'
=>
$query
]
],
[
'id'
=>
'001'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
$query
])
],
[
'id'
=>
'002'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
$query
])
],
[
'id'
=>
'003'
,
'title'
=>
'https://core.telegram.org/bots/api#answerinlinequery'
,
'message_text'
=>
'you enter: '
.
$query
,
'input_message_content'
=>
new
InputTextMessageContent
([
'message_text'
=>
$query
])
],
];
$array_article
=
[];
...
...
src/Entities/Audio.php
View file @
15afa620
...
...
@@ -21,10 +21,8 @@ class Audio extends Entity
protected
$mime_type
;
protected
$file_size
;
public
function
__construct
(
array
$data
)
{
$this
->
file_id
=
isset
(
$data
[
'file_id'
])
?
$data
[
'file_id'
]
:
null
;
if
(
empty
(
$this
->
file_id
))
{
throw
new
TelegramException
(
'file_id is empty!'
);
...
...
@@ -40,7 +38,6 @@ class Audio extends Entity
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
mime_type
=
isset
(
$data
[
'mime_type'
])
?
$data
[
'mime_type'
]
:
null
;
$this
->
file_size
=
isset
(
$data
[
'file_size'
])
?
$data
[
'file_size'
]
:
null
;
}
public
function
getFileId
()
...
...
@@ -57,10 +54,12 @@ class Audio extends Entity
{
return
$this
->
performer
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getMimeType
()
{
return
$this
->
mime_type
;
...
...
src/Entities/Chat.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
Chat
extends
Entity
{
protected
$id
;
protected
$type
;
protected
$title
;
...
...
@@ -81,37 +80,31 @@ class Chat extends Entity
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getType
()
{
return
$this
->
type
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getFirstName
()
{
return
$this
->
first_name
;
}
public
function
getLastName
()
{
return
$this
->
last_name
;
}
public
function
getUsername
()
{
return
$this
->
username
;
}
...
...
src/Entities/ChosenInlineResult.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
ChosenInlineResult
extends
Entity
{
protected
$result_id
;
protected
$from
;
protected
$location
;
...
...
@@ -23,7 +22,6 @@ class ChosenInlineResult extends Entity
public
function
__construct
(
array
$data
)
{
$this
->
result_id
=
isset
(
$data
[
'result_id'
])
?
$data
[
'result_id'
]
:
null
;
if
(
empty
(
$this
->
result_id
))
{
throw
new
TelegramException
(
'result_id is empty!'
);
...
...
src/Entities/Contact.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
Contact
extends
Entity
{
protected
$phone_number
;
protected
$first_name
;
protected
$last_name
;
...
...
@@ -22,7 +21,6 @@ class Contact extends Entity
public
function
__construct
(
array
$data
)
{
$this
->
phone_number
=
isset
(
$data
[
'phone_number'
])
?
$data
[
'phone_number'
]
:
null
;
if
(
empty
(
$this
->
phone_number
))
{
throw
new
TelegramException
(
'phone_number is empty!'
);
...
...
src/Entities/Document.php
View file @
15afa620
...
...
@@ -22,7 +22,6 @@ class Document extends Entity
public
function
__construct
(
array
$data
)
{
$this
->
file_id
=
isset
(
$data
[
'file_id'
])
?
$data
[
'file_id'
]
:
null
;
if
(
empty
(
$this
->
file_id
))
{
throw
new
TelegramException
(
'file_id is empty!'
);
...
...
@@ -36,7 +35,6 @@ class Document extends Entity
$this
->
file_name
=
isset
(
$data
[
'file_name'
])
?
$data
[
'file_name'
]
:
null
;
$this
->
mime_type
=
isset
(
$data
[
'mime_type'
])
?
$data
[
'mime_type'
]
:
null
;
$this
->
file_size
=
isset
(
$data
[
'file_size'
])
?
$data
[
'file_size'
]
:
null
;
}
public
function
getFileId
()
...
...
@@ -46,21 +44,21 @@ class Document extends Entity
public
function
getThumb
()
{
return
$this
->
thumb
;
return
$this
->
thumb
;
}
public
function
getFileName
()
{
return
$this
->
file_name
;
return
$this
->
file_name
;
}
public
function
getMimeType
()
{
return
$this
->
mime_type
;
return
$this
->
mime_type
;
}
public
function
getFileSize
()
{
return
$this
->
file_size
;
return
$this
->
file_size
;
}
}
src/Entities/Entity.php
View file @
15afa620
...
...
@@ -14,10 +14,8 @@ class Entity
{
protected
$bot_name
;
public
function
getBotName
()
{
return
$this
->
bot_name
;
}
...
...
@@ -77,6 +75,9 @@ class Entity
}
elseif
(
$array_of_array_obj
)
{
foreach
(
$object
->
$name
as
$elm
)
{
$temp
=
null
;
if
(
!
is_array
(
$elm
)
&&
!
is_object
(
$elm
))
{
continue
;
}
foreach
(
$elm
as
$obj
)
{
$temp
[]
=
$this
->
reflect
(
$obj
);
}
...
...
src/Entities/File.php
View file @
15afa620
...
...
@@ -20,7 +20,6 @@ class File extends Entity
public
function
__construct
(
array
$data
)
{
$this
->
file_id
=
isset
(
$data
[
'file_id'
])
?
$data
[
'file_id'
]
:
null
;
if
(
empty
(
$this
->
file_id
))
{
throw
new
TelegramException
(
'file_id is empty!'
);
...
...
@@ -29,7 +28,6 @@ class File extends Entity
$this
->
file_size
=
isset
(
$data
[
'file_size'
])
?
$data
[
'file_size'
]
:
null
;
$this
->
file_path
=
isset
(
$data
[
'file_path'
])
?
$data
[
'file_path'
]
:
null
;
}
public
function
getFileId
()
...
...
@@ -39,11 +37,11 @@ class File extends Entity
public
function
getFileSize
()
{
return
$this
->
file_size
;
return
$this
->
file_size
;
}
public
function
getFilePath
()
{
return
$this
->
file_path
;
return
$this
->
file_path
;
}
}
src/Entities/InlineKeyboardButton.php
View file @
15afa620
...
...
@@ -19,6 +19,9 @@ class InlineKeyboardButton extends Entity
protected
$callback_data
;
protected
$switch_inline_query
;
/**
* @todo check if only one of 'url, callback_data, switch_inline_query' fields is set, documentation states that only one of these can be used
*/
public
function
__construct
(
$data
=
array
())
{
$this
->
text
=
isset
(
$data
[
'text'
])
?
$data
[
'text'
]
:
null
;
...
...
@@ -30,12 +33,8 @@ class InlineKeyboardButton extends Entity
$this
->
callback_data
=
isset
(
$data
[
'callback_data'
])
?
$data
[
'callback_data'
]
:
null
;
$this
->
switch_inline_query
=
isset
(
$data
[
'switch_inline_query'
])
?
$data
[
'switch_inline_query'
]
:
null
;
if
(
empty
(
$this
->
url
)
&&
empty
(
$this
->
callback_data
)
&&
empty
(
$this
->
switch_inline_query
)
)
{
if
(
$this
->
url
===
''
&&
$this
->
callback_data
===
''
&&
$this
->
switch_inline_query
===
''
)
{
throw
new
TelegramException
(
'You must use at least one of these fields: url, callback_data, switch_inline_query!'
);
}
/*
* @todo check if only one of 'url, callback_data, switch_inline_query' fields is set, documentation states that only one of these can be used
*/
}
}
src/Entities/InlineKeyboardMarkup.php
View file @
15afa620
...
...
@@ -16,9 +16,6 @@ class InlineKeyboardMarkup extends Entity
{
protected
$inline_keyboard
;
/*
* @todo check for InlineKeyboardButton elements
*/
public
function
__construct
(
$data
=
array
())
{
if
(
isset
(
$data
[
'inline_keyboard'
]))
{
...
...
src/Entities/InlineQuery.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
InlineQuery
extends
Entity
{
protected
$id
;
protected
$from
;
protected
$location
;
...
...
@@ -23,7 +22,6 @@ class InlineQuery extends Entity
public
function
__construct
(
array
$data
)
{
$this
->
id
=
isset
(
$data
[
'id'
])
?
$data
[
'id'
]
:
null
;
if
(
empty
(
$this
->
id
))
{
throw
new
TelegramException
(
'id is empty!'
);
...
...
@@ -48,18 +46,22 @@ class InlineQuery extends Entity
{
return
$this
->
id
;
}
public
function
getFrom
()
{
return
$this
->
from
;
}
public
function
getLocation
()
{
return
$this
->
location
;
}
public
function
getQuery
()
{
return
$this
->
query
;
}
public
function
getOffset
()
{
return
$this
->
offset
;
...
...
src/Entities/InlineQueryResult.php
View file @
15afa620
...
...
@@ -35,8 +35,19 @@ class InlineQueryResult extends Entity
{
return
$this
->
type
;
}
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getInputMessageContent
()
{
return
$this
->
input_message_content
;
}
public
function
getReplyMarkup
()
{
return
$this
->
reply_markup
;
}
}
src/Entities/InlineQueryResultArticle.php
View file @
15afa620
...
...
@@ -45,7 +45,6 @@ class InlineQueryResultArticle extends InlineQueryResult
$this
->
thumb_url
=
isset
(
$data
[
'thumb_url'
])
?
$data
[
'thumb_url'
]
:
null
;
$this
->
thumb_width
=
isset
(
$data
[
'thumb_width'
])
?
$data
[
'thumb_width'
]
:
null
;
$this
->
thumb_height
=
isset
(
$data
[
'thumb_height'
])
?
$data
[
'thumb_height'
]
:
null
;
}
public
function
getTitle
()
...
...
src/Entities/InlineQueryResultCachedAudio.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedAudio
extends
InlineQueryResult
{
protected
$audio_file_id
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'audio'
;
$this
->
audio_file_id
=
isset
(
$data
[
'audio_file_id'
])
?
$data
[
'audio_file_id'
]
:
null
;
if
(
empty
(
$this
->
audio_file_id
))
{
throw
new
TelegramException
(
'audio_file_id is empty!'
);
}
}
public
function
getAudioFileId
()
{
return
$this
->
audio_file_id
;
}
}
src/Entities/InlineQueryResultCachedDocument.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedDocument
extends
InlineQueryResult
{
protected
$document_file_id
;
protected
$title
;
protected
$description
;
protected
$caption
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'document'
;
$this
->
document_file_id
=
isset
(
$data
[
'document_file_id'
])
?
$data
[
'document_file_id'
]
:
null
;
if
(
empty
(
$this
->
document_file_id
))
{
throw
new
TelegramException
(
'document_file_id is empty!'
);
}
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
if
(
empty
(
$this
->
title
))
{
throw
new
TelegramException
(
'title is empty!'
);
}
$this
->
description
=
isset
(
$data
[
'description'
])
?
$data
[
'description'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getDocumentFileId
()
{
return
$this
->
document_file_id
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getDescription
()
{
return
$this
->
description
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
}
}
src/Entities/InlineQueryResultCachedGif.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedGif
extends
InlineQueryResult
{
protected
$gif_file_id
;
protected
$title
;
protected
$description
;
protected
$caption
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'gif'
;
$this
->
gif_file_id
=
isset
(
$data
[
'gif_file_id'
])
?
$data
[
'gif_file_id'
]
:
null
;
if
(
empty
(
$this
->
gif_file_id
))
{
throw
new
TelegramException
(
'gif_file_id is empty!'
);
}
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getGifFileId
()
{
return
$this
->
gif_file_id
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
}
}
src/Entities/InlineQueryResultCachedMpeg4Gif.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedMpeg4Gif
extends
InlineQueryResult
{
protected
$mpeg4_file_id
;
protected
$title
;
protected
$caption
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'mpeg4_gif'
;
$this
->
mpeg4_file_id
=
isset
(
$data
[
'mpeg4_file_id'
])
?
$data
[
'mpeg4_file_id'
]
:
null
;
if
(
empty
(
$this
->
mpeg4_file_id
))
{
throw
new
TelegramException
(
'mpeg4_file_id is empty!'
);
}
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getMpeg4FileId
()
{
return
$this
->
mpeg4_file_id
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
}
}
src/Entities/InlineQueryResultCachedPhoto.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedPhoto
extends
InlineQueryResult
{
protected
$photo_file_id
;
protected
$title
;
protected
$description
;
protected
$caption
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'photo'
;
$this
->
photo_file_id
=
isset
(
$data
[
'photo_file_id'
])
?
$data
[
'photo_file_id'
]
:
null
;
if
(
empty
(
$this
->
photo_file_id
))
{
throw
new
TelegramException
(
'photo_file_id is empty!'
);
}
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
description
=
isset
(
$data
[
'description'
])
?
$data
[
'description'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getPhotoFileId
()
{
return
$this
->
photo_file_id
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getDescription
()
{
return
$this
->
description
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
}
}
src/Entities/InlineQueryResultCachedSticker.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedSticker
extends
InlineQueryResult
{
protected
$sticker_file_id
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'sticker'
;
$this
->
photo_file_id
=
isset
(
$data
[
'sticker_file_id'
])
?
$data
[
'sticker_file_id'
]
:
null
;
if
(
empty
(
$this
->
sticker_file_id
))
{
throw
new
TelegramException
(
'sticker_file_id is empty!'
);
}
}
public
function
getStickerFileId
()
{
return
$this
->
sticker_file_id
;
}
}
src/Entities/InlineQueryResultCachedVideo.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedVideo
extends
InlineQueryResult
{
protected
$video_file_id
;
protected
$title
;
protected
$description
;
protected
$caption
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'photo'
;
$this
->
video_file_id
=
isset
(
$data
[
'video_file_id'
])
?
$data
[
'video_file_id'
]
:
null
;
if
(
empty
(
$this
->
video_file_id
))
{
throw
new
TelegramException
(
'video_file_id is empty!'
);
}
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
if
(
empty
(
$this
->
title
))
{
throw
new
TelegramException
(
'title is empty!'
);
}
$this
->
description
=
isset
(
$data
[
'description'
])
?
$data
[
'description'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getVideoFileId
()
{
return
$this
->
video_file_id
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getDescription
()
{
return
$this
->
description
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
}
}
src/Entities/InlineQueryResultCachedVoice.php
0 → 100644
View file @
15afa620
<?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\Entities
;
use
Longman\TelegramBot\Exception\TelegramException
;
class
InlineQueryResultCachedVoice
extends
InlineQueryResult
{
protected
$voice_file_id
;
protected
$title
;
protected
$description
;
protected
$caption
;
public
function
__construct
(
array
$data
)
{
parent
::
__construct
(
$data
);
$this
->
type
=
'voice'
;
$this
->
voice_file_id
=
isset
(
$data
[
'voice_file_id'
])
?
$data
[
'voice_file_id'
]
:
null
;
if
(
empty
(
$this
->
voice_file_id
))
{
throw
new
TelegramException
(
'voice_file_id is empty!'
);
}
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
if
(
empty
(
$this
->
title
))
{
throw
new
TelegramException
(
'title is empty!'
);
}
$this
->
description
=
isset
(
$data
[
'description'
])
?
$data
[
'description'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getVoiceFileId
()
{
return
$this
->
voice_file_id
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getDescription
()
{
return
$this
->
description
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
}
}
src/Entities/InlineQueryResultGif.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
InlineQueryResultGif
extends
InlineQueryResult
{
protected
$gif_url
;
protected
$gif_width
;
protected
$gif_height
;
...
...
@@ -43,29 +42,33 @@ class InlineQueryResultGif extends InlineQueryResult
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getGifUrl
()
{
return
$this
->
gif_url
;
}
public
function
getGifWidth
()
{
return
$this
->
gif_width
;
}
public
function
getGifHeight
()
{
return
$this
->
gif_height
;
}
public
function
getThumbUrl
()
{
return
$this
->
thumb_url
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
...
...
src/Entities/InlineQueryResultMpeg4Gif.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
InlineQueryResultMpeg4Gif
extends
InlineQueryResult
{
protected
$mpeg4_url
;
protected
$mpeg4_width
;
protected
$mpeg4_height
;
...
...
@@ -43,29 +42,33 @@ class InlineQueryResultMpeg4Gif extends InlineQueryResult
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getMpeg4Url
()
{
return
$this
->
mpeg4_url
;
}
public
function
getMpeg4Width
()
{
return
$this
->
mpeg4_width
;
}
public
function
getMpeg4Height
()
{
return
$this
->
mpeg4_height
;
}
public
function
getThumbUrl
()
{
return
$this
->
thumb_url
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
...
...
src/Entities/InlineQueryResultPhoto.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
InlineQueryResultPhoto
extends
InlineQueryResult
{
protected
$photo_url
;
protected
$photo_width
;
protected
$photo_height
;
...
...
@@ -45,33 +44,38 @@ class InlineQueryResultPhoto extends InlineQueryResult
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
description
=
isset
(
$data
[
'description'
])
?
$data
[
'description'
]
:
null
;
$this
->
caption
=
isset
(
$data
[
'caption'
])
?
$data
[
'caption'
]
:
null
;
}
public
function
getPhotoUrl
()
{
return
$this
->
photo_url
;
}
public
function
getPhotoWidth
()
{
return
$this
->
photo_width
;
}
public
function
getPhotoHeight
()
{
return
$this
->
photo_height
;
}
public
function
getThumbUrl
()
{
return
$this
->
thumb_url
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getDescription
()
{
return
$this
->
description
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
...
...
src/Entities/InlineQueryResultVideo.php
View file @
15afa620
...
...
@@ -14,7 +14,6 @@ use Longman\TelegramBot\Exception\TelegramException;
class
InlineQueryResultVideo
extends
InlineQueryResult
{
protected
$video_url
;
protected
$mime_type
;
protected
$thumb_url
;
...
...
@@ -56,34 +55,42 @@ class InlineQueryResultVideo extends InlineQueryResult
{
return
$this
->
video_url
;
}
public
function
getMimeType
()
{
return
$this
->
mime_type
;
}
public
function
getThumbUrl
()
{
return
$this
->
thumb_url
;
}
public
function
getTitle
()
{
return
$this
->
title
;
}
public
function
getCaption
()
{
return
$this
->
caption
;
}
public
function
getVideoWidth
()
{
return
$this
->
video_width
;
}
public
function
getVideoHeight
()
{
return
$this
->
video_height
;
}
public
function
getVideoDuration
()
{
return
$this
->
video_duration
;
}
public
function
getDescription
()
{
return
$this
->
description
;
...
...
src/Entities/InputContactMessageContent.php
View file @
15afa620
...
...
@@ -20,18 +20,16 @@ class InputContactMessageContent extends InputMessageContent
public
function
__construct
(
array
$data
)
{
//parent::__construct($data);
$this
->
phone_number
isset
(
$data
[
'phone_number'
])
?
$data
[
'phone_number'
]
:
null
;
$this
->
phone_number
=
isset
(
$data
[
'phone_number'
])
?
$data
[
'phone_number'
]
:
null
;
if
(
empty
(
$this
->
phone_number
))
{
throw
new
TelegramException
(
'phone_number is empty!'
);
}
$this
->
first_name
isset
(
$data
[
'first_name'
])
?
$data
[
'first_name'
]
:
null
;
$this
->
first_name
=
isset
(
$data
[
'first_name'
])
?
$data
[
'first_name'
]
:
null
;
if
(
empty
(
$this
->
first_name
))
{
throw
new
TelegramException
(
'first_name is empty!'
);
}
$this
->
last_name
isset
(
$data
[
'last_name'
])
?
$data
[
'last_name'
]
:
null
;
$this
->
last_name
=
isset
(
$data
[
'last_name'
])
?
$data
[
'last_name'
]
:
null
;
}
}
src/Entities/InputLocationMessageContent.php
View file @
15afa620
...
...
@@ -19,14 +19,12 @@ class InputLocationMessageContent extends InputMessageContent
public
function
__construct
(
array
$data
)
{
//parent::__construct($data);
$this
->
latitude
isset
(
$data
[
'latitude'
])
?
$data
[
'latitude'
]
:
null
;
$this
->
latitude
=
isset
(
$data
[
'latitude'
])
?
$data
[
'latitude'
]
:
null
;
if
(
empty
(
$this
->
latitude
))
{
throw
new
TelegramException
(
'latitude is empty!'
);
}
$this
->
longitude
isset
(
$data
[
'longitude'
])
?
$data
[
'longitude'
]
:
null
;
$this
->
longitude
=
isset
(
$data
[
'longitude'
])
?
$data
[
'longitude'
]
:
null
;
if
(
empty
(
$this
->
longitude
))
{
throw
new
TelegramException
(
'longitude is empty!'
);
}
...
...
src/Entities/InputTextMessageContent.php
View file @
15afa620
...
...
@@ -20,14 +20,12 @@ class InputTextMessageContent extends InputMessageContent
public
function
__construct
(
array
$data
)
{
//parent::__construct($data);
$this
->
message_text
isset
(
$data
[
'message_text'
])
?
$data
[
'message_text'
]
:
null
;
$this
->
message_text
=
isset
(
$data
[
'message_text'
])
?
$data
[
'message_text'
]
:
null
;
if
(
empty
(
$this
->
message_text
))
{
throw
new
TelegramException
(
'message_text is empty!'
);
}
$this
->
parse_mode
isset
(
$data
[
'parse_mode'
])
?
$data
[
'parse_mode'
]
:
null
;
$this
->
disable_web_page_preview
isset
(
$data
[
'disable_web_page_preview'
])
?
$data
[
'disable_web_page_preview'
]
:
null
;
$this
->
parse_mode
=
isset
(
$data
[
'parse_mode'
])
?
$data
[
'parse_mode'
]
:
null
;
$this
->
disable_web_page_preview
=
isset
(
$data
[
'disable_web_page_preview'
])
?
$data
[
'disable_web_page_preview'
]
:
null
;
}
}
src/Entities/InputVenueMessageContent.php
View file @
15afa620
...
...
@@ -22,28 +22,26 @@ class InputVenueMessageContent extends InputMessageContent
public
function
__construct
(
array
$data
)
{
//parent::__construct($data);
$this
->
latitude
isset
(
$data
[
'latitude'
])
?
$data
[
'latitude'
]
:
null
;
$this
->
latitude
=
isset
(
$data
[
'latitude'
])
?
$data
[
'latitude'
]
:
null
;
if
(
empty
(
$this
->
latitude
))
{
throw
new
TelegramException
(
'latitude is empty!'
);
}
$this
->
longitude
isset
(
$data
[
'longitude'
])
?
$data
[
'longitude'
]
:
null
;
$this
->
longitude
=
isset
(
$data
[
'longitude'
])
?
$data
[
'longitude'
]
:
null
;
if
(
empty
(
$this
->
longitude
))
{
throw
new
TelegramException
(
'longitude is empty!'
);
}
$this
->
title
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
$this
->
title
=
isset
(
$data
[
'title'
])
?
$data
[
'title'
]
:
null
;
if
(
empty
(
$this
->
title
))
{
throw
new
TelegramException
(
'title is empty!'
);
}
$this
->
address
isset
(
$data
[
'address'
])
?
$data
[
'address'
]
:
null
;
$this
->
address
=
isset
(
$data
[
'address'
])
?
$data
[
'address'
]
:
null
;
if
(
empty
(
$this
->
address
))
{
throw
new
TelegramException
(
'address is empty!'
);
}
$this
->
foursquare_id
isset
(
$data
[
'foursquare_id'
])
?
$data
[
'foursquare_id'
]
:
null
;
$this
->
foursquare_id
=
isset
(
$data
[
'foursquare_id'
])
?
$data
[
'foursquare_id'
]
:
null
;
}
}
src/Entities/Message.php
View file @
15afa620
...
...
@@ -122,7 +122,6 @@ class Message extends Entity
$this
->
forward_from
=
isset
(
$data
[
'forward_from'
])
?
$data
[
'forward_from'
]
:
null
;
if
(
!
empty
(
$this
->
forward_from
))
{
$this
->
forward_from
=
new
User
(
$this
->
forward_from
);
}
$this
->
forward_from_chat
=
isset
(
$data
[
'forward_from_chat'
])
?
$data
[
'forward_from_chat'
]
:
null
;
...
...
src/Entities/MessageEntity.php
View file @
15afa620
...
...
@@ -17,20 +17,23 @@ class MessageEntity extends Entity
protected
$length
;
protected
$url
;
/**
* @todo check for type value from this list: https://core.telegram.org/bots/api#messageentity
*/
public
function
__construct
(
array
$data
)
{
$this
->
type
=
isset
(
$data
[
'type'
])
?
$data
[
'type'
]
:
null
;
if
(
empty
(
$this
->
type
))
{
// @todo check for value from this list: https://core.telegram.org/bots/api#messageentity
if
(
empty
(
$this
->
type
))
{
throw
new
TelegramException
(
'type is empty!'
);
}
$this
->
offset
=
isset
(
$data
[
'offset'
])
?
$data
[
'offset'
]
:
null
;
if
(
empty
(
$this
->
offset
)
&&
$this
->
offset
!=
0
)
{
// @todo this is not an ideal solution?
if
(
$this
->
offset
===
''
)
{
throw
new
TelegramException
(
'offset is empty!'
);
}
$this
->
length
=
isset
(
$data
[
'length'
])
?
$data
[
'length'
]
:
null
;
if
(
empty
(
$this
->
length
)
&&
$this
->
offset
!=
0
)
{
// @todo this is not an ideal solution?
if
(
$this
->
length
===
''
)
{
throw
new
TelegramException
(
'length is empty!'
);
}
...
...
src/Entities/ReplyKeyboardMarkup.php
View file @
15afa620
...
...
@@ -21,9 +21,6 @@ class ReplyKeyboardMarkup extends Entity
protected
$one_time_keyboard
;
protected
$selective
;
/*
* @todo check for KeyboardButton elements
*/
public
function
__construct
(
$data
=
array
())
{
if
(
isset
(
$data
[
'keyboard'
]))
{
...
...
src/Request.php
View file @
15afa620
...
...
@@ -222,6 +222,8 @@ class Request
self
::
log
(
$result
);
}
curl_close
(
$ch
);
if
(
$result
===
false
)
{
throw
new
TelegramException
(
curl_error
(
$ch
),
curl_errno
(
$ch
));
}
...
...
@@ -229,7 +231,6 @@ class Request
throw
new
TelegramException
(
'Empty server response'
);
}
curl_close
(
$ch
);
return
$result
;
}
...
...
src/Telegram.php
View file @
15afa620
...
...
@@ -137,6 +137,13 @@ class Telegram
*/
protected
$last_command_response
;
/**
* Botan.io integration
*
* @var boolean
*/
protected
$botan_enabled
=
false
;
/**
* Constructor
*
...
...
@@ -511,6 +518,11 @@ class Telegram
//execute() method is executed after preExecute()
//This is to prevent executing a DB query without a valid connection
$this
->
last_command_response
=
$command_obj
->
preExecute
();
//Botan.io integration
if
(
$this
->
botan_enabled
)
{
Botan
::
track
(
$this
->
update
,
$command
);
}
}
return
$this
->
last_command_response
;
...
...
@@ -568,6 +580,12 @@ class Telegram
if
(
$user_id
===
null
&&
$this
->
update
!==
null
)
{
if
((
$message
=
$this
->
update
->
getMessage
())
&&
(
$from
=
$message
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
}
elseif
((
$inline_query
=
$this
->
update
->
getInlineQuery
())
&&
(
$from
=
$inline_query
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
}
elseif
((
$callback_query
=
$this
->
update
->
getCallbackQuery
())
&&
(
$from
=
$callback_query
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
}
elseif
((
$chosen_inline_result
=
$this
->
update
->
getChosenInlineResult
())
&&
(
$from
=
$chosen_inline_result
->
getFrom
()))
{
$user_id
=
$from
->
getId
();
}
}
...
...
@@ -785,4 +803,18 @@ class Telegram
{
return
mb_strtoupper
(
mb_substr
(
$str
,
0
,
1
,
$encoding
),
$encoding
)
.
mb_strtolower
(
mb_substr
(
$str
,
1
,
mb_strlen
(
$str
),
$encoding
),
$encoding
);
}
/**
* Enable Botan.io integration
*
* @param $token
* @param $custom
* @return Telegram
*/
public
function
enableBotan
(
$token
)
{
Botan
::
initializeBotan
(
$token
);
$this
->
botan_enabled
=
true
;
return
$this
;
}
}
structure.sql
View file @
15afa620
...
...
@@ -40,8 +40,7 @@ CREATE TABLE IF NOT EXISTS `inline_query` (
PRIMARY
KEY
(
`id`
),
KEY
`user_id`
(
`user_id`
),
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_520_ci
;
...
...
@@ -56,8 +55,7 @@ CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
PRIMARY
KEY
(
`id`
),
KEY
`user_id`
(
`user_id`
),
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_520_ci
;
...
...
@@ -71,8 +69,7 @@ CREATE TABLE IF NOT EXISTS `callback_query` (
PRIMARY
KEY
(
`id`
),
KEY
`user_id`
(
`user_id`
),
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_520_ci
;
...
...
@@ -166,8 +163,18 @@ CREATE TABLE IF NOT EXISTS `conversation` (
KEY
`chat_id`
(
`chat_id`
),
KEY
`status`
(
`status`
),
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
),
FOREIGN
KEY
(
`chat_id`
)
REFERENCES
`chat`
(
`id`
)
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
),
FOREIGN
KEY
(
`chat_id`
)
REFERENCES
`chat`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_520_ci
;
CREATE
TABLE
IF
NOT
EXISTS
`botan_shortener`
(
`id`
bigint
UNSIGNED
AUTO_INCREMENT
COMMENT
'Unique identifier for this entry.'
,
`user_id`
bigint
NULL
DEFAULT
NULL
COMMENT
'Unique user identifier'
,
`url`
text
NOT
NULL
DEFAULT
''
COMMENT
'Original URL'
,
`short_url`
CHAR
(
255
)
NOT
NULL
DEFAULT
''
COMMENT
'Shortened URL'
,
`created_at`
timestamp
NULL
DEFAULT
NULL
COMMENT
'Entry date creation'
,
PRIMARY
KEY
(
`id`
),
FOREIGN
KEY
(
`user_id`
)
REFERENCES
`user`
(
`id`
)
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_520_ci
;
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