1 | <?php |
||
32 | class InlineQueryResults |
||
33 | { |
||
34 | /** |
||
35 | * \addtogroup InlineQueryResults InlineQueryResults |
||
36 | * \brief Handles and stores results before sending them to an answerInlineQuery API call. |
||
37 | * \details In order to answer <i>inline queries</i>: create an object of type |
||
38 | * PhpBotFramework\Entities\InlineQueryResults and add the wanted results |
||
39 | * using InlineQueryResults::addResult() method or |
||
40 | * type-based result method (InlineQueryResults::newArticle()). |
||
41 | * |
||
42 | * use PhpBotFramework\Entities\InlineQueryResults; |
||
43 | * use PhpBotFramework\Entities\InlineQuery; |
||
44 | * ~ |
||
45 | * ~ |
||
46 | * ~ |
||
47 | * processInlineQuery(InlineQuery $inline_query) { |
||
48 | * $handler = new InlineQueryResults(); |
||
49 | * $handler->newArticle('First article', 'This is the first result'); |
||
50 | * |
||
51 | * $this->answerInlineQuery($handler->get()); |
||
52 | * } |
||
53 | * |
||
54 | * @{ |
||
55 | */ |
||
56 | |||
57 | /** \brief Array of the results stored. */ |
||
58 | private $results; |
||
59 | |||
60 | /** \brief Counts the result so we can assign them an unique id. */ |
||
61 | private $id_result; |
||
62 | |||
63 | /** \brief Accepted types for results. */ |
||
64 | private $accepted_type = [ |
||
65 | 'audio', |
||
66 | 'article', |
||
67 | 'photo', |
||
68 | 'gif', |
||
69 | 'mpeg4_gif', |
||
70 | 'video', |
||
71 | 'voice', |
||
72 | 'document', |
||
73 | 'location', |
||
74 | 'venue', |
||
75 | 'contact', |
||
76 | 'game' |
||
77 | ]; |
||
78 | |||
79 | /** |
||
80 | * \constructor Create an InlineQueryResult object. */ |
||
81 | public function __construct() |
||
87 | |||
88 | /** |
||
89 | * \brief Add a result passing an array containing data. |
||
90 | * \details Create a result of one of these types: |
||
91 | * - InlineQueryResultCachedAudio |
||
92 | * - InlineQueryResultCachedDocument |
||
93 | * - InlineQueryResultCachedGif |
||
94 | * - InlineQueryResultCachedMpeg4Gif |
||
95 | * - InlineQueryResultCachedPhoto |
||
96 | * - InlineQueryResultCachedSticker |
||
97 | * - InlineQueryResultCachedVideo |
||
98 | * - InlineQueryResultCachedVoice |
||
99 | * - InlineQueryResultArticle |
||
100 | * - InlineQueryResultAudio |
||
101 | * - InlineQueryResultContact |
||
102 | * - InlineQueryResultGame |
||
103 | * - InlineQueryResultDocument |
||
104 | * - InlineQueryResultGif |
||
105 | * - InlineQueryResultLocation |
||
106 | * - InlineQueryResultMpeg4Gif |
||
107 | * - InlineQueryResultPhoto |
||
108 | * - InlineQueryResultVenue |
||
109 | * - InlineQueryResultVideo |
||
110 | * - InlineQueryResultVoice |
||
111 | * |
||
112 | * To add a result, create an array containing data as showed on API Reference, |
||
113 | *'id' parameter will be automatically genereted so there is no need to add it. |
||
114 | * |
||
115 | * Example of adding an article result: |
||
116 | * |
||
117 | * $data = [ |
||
118 | * 'type' => 'result', |
||
119 | * 'title' => 'Example title', |
||
120 | * 'message_text' => 'Text of the message' |
||
121 | * ]; |
||
122 | * |
||
123 | * $handler->addResult($data); |
||
124 | * |
||
125 | * @param array $result Array containing data result to add. |
||
126 | * @return int Id of the result added. |
||
127 | */ |
||
128 | public function addResult(array $result) : int |
||
140 | |||
141 | /** |
||
142 | * \brief Add a result of type Article. |
||
143 | * \details Add a result that will be show to the user. |
||
144 | * @param string $title Title of the result. |
||
145 | * @param string $message_text Text of the message to be sent. |
||
146 | * @param string $description <i>Optional</i>. Short description of the result |
||
147 | * @param array $reply_markup Inline keyboard object. |
||
148 | * Not JSON serialized, use getArray from InlineKeyboard class. |
||
149 | * @param string $parse_mode <i>Optional</i>. Formattation style for the message. |
||
150 | * @param string $disable_web_preview <i>Optional</i>. Disables link previews for |
||
151 | * links in the sent message. |
||
152 | * @return int Id the the article added. |
||
153 | */ |
||
154 | public function newArticle( |
||
180 | |||
181 | /** |
||
182 | * \brief Get all results created. |
||
183 | * @return string JSON string containing the results. |
||
184 | */ |
||
185 | public function get() |
||
195 | |||
196 | /** @} */ |
||
197 | |||
198 | /** @} */ |
||
199 | } |
||
200 |