1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Telegram\Bot\Answers; |
4
|
|
|
|
5
|
|
|
use Telegram\Bot\Api; |
6
|
|
|
use Telegram\Bot\Objects\Update; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class Answer |
10
|
|
|
* |
11
|
|
|
* @method mixed replyWithMessage($use_sendMessage_parameters) Reply Chat with a message. You can use all the sendMessage() parameters except chat_id. |
12
|
|
|
* @method mixed replyWithPhoto($use_sendPhoto_parameters) Reply Chat with a Photo. You can use all the sendPhoto() parameters except chat_id. |
13
|
|
|
* @method mixed replyWithAudio($use_sendAudio_parameters) Reply Chat with an Audio message. You can use all the sendAudio() parameters except chat_id. |
14
|
|
|
* @method mixed replyWithVideo($use_sendVideo_parameters) Reply Chat with a Video. You can use all the sendVideo() parameters except chat_id. |
15
|
|
|
* @method mixed replyWithVoice($use_sendVoice_parameters) Reply Chat with a Voice message. You can use all the sendVoice() parameters except chat_id. |
16
|
|
|
* @method mixed replyWithDocument($use_sendDocument_parameters) Reply Chat with a Document. You can use all the sendDocument() parameters except chat_id. |
17
|
|
|
* @method mixed replyWithSticker($use_sendSticker_parameters) Reply Chat with a Sticker. You can use all the sendSticker() parameters except chat_id. |
18
|
|
|
* @method mixed replyWithLocation($use_sendLocation_parameters) Reply Chat with a Location. You can use all the sendLocation() parameters except chat_id. |
19
|
|
|
* @method mixed replyWithChatAction($use_sendChatAction_parameters) Reply Chat with a Chat Action. You can use all the sendChatAction() parameters except chat_id. |
20
|
|
|
*/ |
21
|
|
|
trait Answerable |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var Api Holds the Super Class Instance. |
25
|
|
|
*/ |
26
|
|
|
protected $telegram; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Update Holds an Update object. |
30
|
|
|
*/ |
31
|
|
|
protected $update; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Magic Method to handle all ReplyWith Methods. |
35
|
|
|
* |
36
|
|
|
* @param $method |
37
|
|
|
* @param $arguments |
38
|
|
|
* |
39
|
|
|
* @return mixed|string |
40
|
|
|
*/ |
41
|
|
|
public function __call($method, $arguments) |
42
|
|
|
{ |
43
|
|
|
$action = substr($method, 0, 9); |
44
|
|
|
if ($action === 'replyWith') { |
45
|
|
|
$reply_name = studly_case(substr($method, 9)); |
46
|
|
|
$methodName = 'send' . $reply_name; |
47
|
|
|
|
48
|
|
|
if (!method_exists($this->telegram, $methodName)) { |
49
|
|
|
throw new \BadMethodCallException("Method [$method] does not exist."); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$chat_id = $this->update->getMessage()->getChat()->getId(); |
53
|
|
|
$params = array_merge(compact('chat_id'), $arguments[0]); |
54
|
|
|
|
55
|
|
|
return call_user_func_array([$this->telegram, $methodName], [$params]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
throw new \BadMethodCallException("Method [$method] does not exist."); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return Api |
63
|
|
|
*/ |
64
|
|
|
public function getTelegram() |
65
|
|
|
{ |
66
|
|
|
return $this->telegram; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return Update |
71
|
|
|
*/ |
72
|
|
|
public function getUpdate() |
73
|
|
|
{ |
74
|
|
|
return $this->update; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|