Commit adcc2041 authored by MBoretto's avatar MBoretto

Article works:w

parent d203e113
......@@ -13,6 +13,8 @@ namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\InlineQueryResultArticle;
use Longman\TelegramBot\Entities\Entity;
class InlinequeryCommand extends Command
{
......@@ -27,49 +29,25 @@ class InlinequeryCommand extends Command
{
$update = $this->getUpdate();
$inline_query = $update->getInlineQuery();
//$inline_query->getQuery();
//$update->getUpdateId();
$data = array();
$data['inline_query_id']= $update->getUpdateId();
$data['inline_query_id']= (string) time();
//$data['cache_time']=60;
//$data['is_personal']="false";
//$data['next_offset']="122;
$data['results']='[
{
"type": "article",
"id": "001",
"title": "UC Browser",
"message_text": "Text of the first message",
"parse_mode": "Markdown",
"disable_web_page_preview": true,
"url": "telegram.com",
"hide_url": true,
"description": "Optional. Short description of the result",
"thumb_url": "http://icons.iconarchive.com/icons/martz90/circle/64/uc-browser-icon.png",
"thumb_width": 64,
"thumb_height": 64
},
{
"type": "article",
"id": "002",
"title": "Bitcoin",
"message_text": "*Text of the second message*",
"parse_mode": "Markdown",
"disable_web_page_preview": true,
"url": "bitcoin.org",
"hide_url": true,
"description": "Short description of the result",
"thumb_url": "http://www.coinwarz.com/content/images/bitcoin-64x64.png",
"thumb_width": 64,
"thumb_height": 64
}
]';
$query = $inline_query->getQuery();
$result = Request::answerInlineQuery($data);
$data = [];
$data['inline_query_id']= $inline_query->getId();
$articles = [];
$articles[] = ['id' => '001' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: '.$query ];
$articles[] = ['id' => '002' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: '.$query ];
$articles[] = ['id' => '003' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: '.$query ];
$array_article = [];
foreach ($articles as $article) {
$array_article[] = new InlineQueryResultArticle($article);
}
$array_json = '['.implode(',', $array_article).']';
$data['results'] = $array_json;
$result = Request::answerInlineQuery($data);
return $result->isOk();
//return 1;
}
}
......@@ -43,7 +43,7 @@ class InlineQuery extends Entity
return $this->id;
}
public function geFrom()
public function getFrom()
{
return $this->from;
}
......
<?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 InlineQueryResultArticle extends Entity
{
protected $type;
protected $id;
protected $title;
protected $message_text;
protected $parse_mode;
protected $disable_web_page_preview;
protected $url;
protected $hide_url;
protected $description;
protected $thumb_url;
protected $thumb_width;
protected $thumb_height;
public function __construct(array $data)
{
$this->type = 'article';
$this->id = isset($data['id']) ? $data['id'] : null;
if (empty($this->id)) {
throw new TelegramException('id is empty!');
}
$this->title = isset($data['title']) ? $data['title'] : null;
if (empty($this->title)) {
throw new TelegramException('title is empty!');
}
$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_webpage_preview']) ? $data['disable_webpage_preview'] : null;
$this->url = isset($data['url']) ? $data['url'] : null;
$this->hide_url = isset($data['hide_url']) ? $data['hide_url'] : null;
$this->description = isset($data['description']) ? $data['description'] : null;
$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 getType()
{
return $this->type;
}
public function getId()
{
return $this->id;
}
public function getTitle()
{
return $this->title;
}
public function getMessageText()
{
return $this->message_text;
}
public function getParseMode()
{
return $this->parse_mode;
}
public function getDisableWebPagePreview()
{
return $this->disable_web_page_preview;
}
public function getUrl()
{
return $this->url;
}
public function getHideUrl()
{
return $this->hide_url;
}
public function getDescription()
{
return $this->description;
}
public function getThumbUrl()
{
return $this->thumb_url;
}
public function getThumbWidth()
{
return $this->thumb_width;
}
public function getThumbHeight()
{
return $this->thumb_height;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment