Skip to content

Commit adcc204

Browse files
committed
Article works:w
1 parent d203e11 commit adcc204

File tree

3 files changed

+138
-41
lines changed

3 files changed

+138
-41
lines changed

src/Commands/InlinequeryCommand.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Longman\TelegramBot\Request;
1414
use Longman\TelegramBot\Command;
1515
use Longman\TelegramBot\Entities\Update;
16+
use Longman\TelegramBot\Entities\InlineQueryResultArticle;
17+
use Longman\TelegramBot\Entities\Entity;
1618

1719
class InlinequeryCommand extends Command
1820
{
@@ -27,49 +29,25 @@ public function execute()
2729
{
2830
$update = $this->getUpdate();
2931
$inline_query = $update->getInlineQuery();
30-
//$inline_query->getQuery();
31-
//$update->getUpdateId();
32-
$data = array();
33-
$data['inline_query_id']= $update->getUpdateId();
34-
$data['inline_query_id']= (string) time();
35-
//$data['cache_time']=60;
36-
//$data['is_personal']="false";
37-
//$data['next_offset']="122;
38-
$data['results']='[
39-
{
40-
"type": "article",
41-
"id": "001",
42-
"title": "UC Browser",
43-
"message_text": "Text of the first message",
44-
"parse_mode": "Markdown",
45-
"disable_web_page_preview": true,
46-
"url": "telegram.com",
47-
"hide_url": true,
48-
"description": "Optional. Short description of the result",
49-
"thumb_url": "http://icons.iconarchive.com/icons/martz90/circle/64/uc-browser-icon.png",
50-
"thumb_width": 64,
51-
"thumb_height": 64
52-
},
53-
{
54-
"type": "article",
55-
"id": "002",
56-
"title": "Bitcoin",
57-
"message_text": "*Text of the second message*",
58-
"parse_mode": "Markdown",
59-
"disable_web_page_preview": true,
60-
"url": "bitcoin.org",
61-
"hide_url": true,
62-
"description": "Short description of the result",
63-
"thumb_url": "http://www.coinwarz.com/content/images/bitcoin-64x64.png",
64-
"thumb_width": 64,
65-
"thumb_height": 64
66-
}
67-
]';
32+
$query = $inline_query->getQuery();
6833

69-
$result = Request::answerInlineQuery($data);
34+
$data = [];
35+
$data['inline_query_id']= $inline_query->getId();
36+
37+
$articles = [];
38+
$articles[] = ['id' => '001' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: '.$query ];
39+
$articles[] = ['id' => '002' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: '.$query ];
40+
$articles[] = ['id' => '003' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: '.$query ];
7041

42+
$array_article = [];
43+
foreach ($articles as $article) {
44+
$array_article[] = new InlineQueryResultArticle($article);
45+
}
46+
$array_json = '['.implode(',', $array_article).']';
47+
$data['results'] = $array_json;
48+
49+
$result = Request::answerInlineQuery($data);
7150

7251
return $result->isOk();
73-
//return 1;
7452
}
7553
}

src/Entities/InlineQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getId()
4343
return $this->id;
4444
}
4545

46-
public function geFrom()
46+
public function getFrom()
4747
{
4848
return $this->from;
4949
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the TelegramBot package.
5+
*
6+
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
namespace Longman\TelegramBot\Entities;
12+
13+
use Longman\TelegramBot\Exception\TelegramException;
14+
15+
class InlineQueryResultArticle extends Entity
16+
{
17+
protected $type;
18+
protected $id;
19+
protected $title;
20+
protected $message_text;
21+
protected $parse_mode;
22+
protected $disable_web_page_preview;
23+
protected $url;
24+
protected $hide_url;
25+
protected $description;
26+
protected $thumb_url;
27+
protected $thumb_width;
28+
protected $thumb_height;
29+
30+
public function __construct(array $data)
31+
{
32+
33+
$this->type = 'article';
34+
35+
$this->id = isset($data['id']) ? $data['id'] : null;
36+
if (empty($this->id)) {
37+
throw new TelegramException('id is empty!');
38+
}
39+
40+
$this->title = isset($data['title']) ? $data['title'] : null;
41+
if (empty($this->title)) {
42+
throw new TelegramException('title is empty!');
43+
}
44+
45+
$this->message_text = isset($data['message_text']) ? $data['message_text'] : null;
46+
if (empty($this->message_text)) {
47+
throw new TelegramException('message_text is empty!');
48+
}
49+
50+
$this->parse_mode = isset($data['parse_mode']) ? $data['parse_mode'] : null;
51+
$this->disable_web_page_preview = isset($data['disable_webpage_preview']) ? $data['disable_webpage_preview'] : null;
52+
$this->url = isset($data['url']) ? $data['url'] : null;
53+
$this->hide_url = isset($data['hide_url']) ? $data['hide_url'] : null;
54+
$this->description = isset($data['description']) ? $data['description'] : null;
55+
$this->thumb_url = isset($data['thumb_url']) ? $data['thumb_url'] : null;
56+
$this->thumb_width = isset($data['thumb_width']) ? $data['thumb_width'] : null;
57+
$this->thumb_height = isset($data['thumb_height']) ? $data['thumb_height'] : null;
58+
59+
}
60+
61+
public function getType()
62+
{
63+
return $this->type;
64+
}
65+
public function getId()
66+
{
67+
return $this->id;
68+
}
69+
70+
public function getTitle()
71+
{
72+
return $this->title;
73+
}
74+
75+
public function getMessageText()
76+
{
77+
return $this->message_text;
78+
}
79+
80+
public function getParseMode()
81+
{
82+
return $this->parse_mode;
83+
}
84+
85+
public function getDisableWebPagePreview()
86+
{
87+
return $this->disable_web_page_preview;
88+
}
89+
90+
public function getUrl()
91+
{
92+
return $this->url;
93+
}
94+
95+
public function getHideUrl()
96+
{
97+
return $this->hide_url;
98+
}
99+
100+
public function getDescription()
101+
{
102+
return $this->description;
103+
}
104+
105+
public function getThumbUrl()
106+
{
107+
return $this->thumb_url;
108+
}
109+
110+
public function getThumbWidth()
111+
{
112+
return $this->thumb_width;
113+
}
114+
115+
public function getThumbHeight()
116+
{
117+
return $this->thumb_height;
118+
}
119+
}

0 commit comments

Comments
 (0)