Skip to content

implement getWebhookInfo method #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Entities/ServerResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public function __construct(array $data, $bot_name)
} elseif (isset($data['result']['user'])) {
//Response from getChatMember
$this->result = new ChatMember($data['result']);
} elseif (isset($data['result']['has_custom_certificate'])) {
//Response from getWebhookInfo
$this->result = new WebhookInfo($data['result']);
} else {
//Response from sendMessage
$this->result = new Message($data['result'], $bot_name);
Expand Down
83 changes: 83 additions & 0 deletions src/Entities/WebhookInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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 WebhookInfo extends Entity
{
protected $url; // String Webhook URL, may be empty if webhook is not set up
protected $has_custom_certificate; // Boolean True, if a custom certificate was provided for webhook certificate checks
protected $pending_update_count; // Integer Number of updates awaiting delivery
protected $last_error_date; // Integer Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook
protected $last_error_message; // String Optional. Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook

public function __construct(array $data)
{
$this->url = isset($data['url']) ? $data['url'] : null;
$this->has_custom_certificate = isset($data['has_custom_certificate']) ? $data['has_custom_certificate'] : null;
$this->pending_update_count = isset($data['pending_update_count']) ? $data['pending_update_count'] : null;
$this->last_error_date = isset($data['last_error_date']) ? $data['last_error_date'] : null;
$this->last_error_message = isset($data['last_error_message']) ? $data['last_error_message'] : null;
}

/**
* Webhook URL, may be empty if webhook is not set up.
*
* @return string
*/
public function getUrl()
{
return $this->url;
}

/**
* True, if a custom certificate was provided for webhook certificate checks.
*
* @return bool
*/
public function getHasCustomCertificate()
{
return $this->has_custom_certificate;
}

/**
* Number of updates awaiting delivery.
*
* @return int
*/
public function getPendingUpdateCount()
{
return $this->pending_update_count;
}

/**
* Optional.
* Unix time for the most recent error that happened when trying to deliver an update via webhook.
*
* @return int
*/
public function getLastErrorDate()
{
return $this->last_error_date;
}

/**
* Optional.
* Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook.
*
* @return string
*/
public function getLastErrorMessage()
{
return $this->last_error_message;
}
}
11 changes: 11 additions & 0 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Request
'editMessageText',
'editMessageCaption',
'editMessageReplyMarkup',
'getWebhookInfo',
];

/**
Expand Down Expand Up @@ -842,4 +843,14 @@ public static function sendToActiveChats(

return $results;
}

/**
* Use this method to get current webhook status.
*
* @return Entities\ServerResponse
*/
public static function getWebhookInfo()
{
return self::send('getWebhookInfo', []);
}
}