Use new deleteWebhook method to delete a webhook.

Fix some error outputs.
parent 070a08fa
...@@ -8,8 +8,8 @@ try { ...@@ -8,8 +8,8 @@ try {
// Create Telegram API object // Create Telegram API object
$telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME); $telegram = new Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);
// Unset webhook // Delete webhook
$result = $telegram->unsetWebhook(); $result = $telegram->deleteWebhook();
if ($result->isOk()) { if ($result->isOk()) {
echo $result->getDescription(); echo $result->getDescription();
......
...@@ -54,6 +54,7 @@ class Request ...@@ -54,6 +54,7 @@ class Request
private static $actions = [ private static $actions = [
'getUpdates', 'getUpdates',
'setWebhook', 'setWebhook',
'deleteWebhook',
'getMe', 'getMe',
'sendMessage', 'sendMessage',
'forwardMessage', 'forwardMessage',
...@@ -282,7 +283,7 @@ class Request ...@@ -282,7 +283,7 @@ class Request
{ {
$fp = fopen($file, 'r'); $fp = fopen($file, 'r');
if ($fp === false) { if ($fp === false) {
throw new TelegramException('Cannot open ' . $file . ' for reading'); throw new TelegramException('Cannot open "' . $file . '" for reading');
} }
return $fp; return $fp;
...@@ -346,7 +347,7 @@ class Request ...@@ -346,7 +347,7 @@ class Request
private static function ensureValidAction($action) private static function ensureValidAction($action)
{ {
if (!in_array($action, self::$actions, true)) { if (!in_array($action, self::$actions, true)) {
throw new TelegramException('The action " . $action . " doesn\'t exist!'); throw new TelegramException('The action "' . $action . '" doesn\'t exist!');
} }
} }
...@@ -398,7 +399,7 @@ class Request ...@@ -398,7 +399,7 @@ class Request
do { do {
//Chop off and send the first message //Chop off and send the first message
$data['text'] = mb_substr($text, 0, 4096); $data['text'] = mb_substr($text, 0, 4096);
$response = self::send('sendMessage', $data); $response = self::send('sendMessage', $data);
//Prepare the next message //Prepare the next message
$text = mb_substr($text, 4096); $text = mb_substr($text, 4096);
...@@ -807,7 +808,7 @@ class Request ...@@ -807,7 +808,7 @@ class Request
*/ */
public static function setWebhook($url = '', array $data = []) public static function setWebhook($url = '', array $data = [])
{ {
$data = array_intersect_key($data, array_flip([ $data = array_intersect_key($data, array_flip([
'certificate', 'certificate',
'max_connections', 'max_connections',
'allowed_updates', 'allowed_updates',
...@@ -821,6 +822,20 @@ class Request ...@@ -821,6 +822,20 @@ class Request
return self::send('setWebhook', $data); return self::send('setWebhook', $data);
} }
/**
* Delete webhook
*
* @link https://core.telegram.org/bots/api#deletewebhook
*
* @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function deleteWebhook()
{
// Must send some arbitrary data for this to work for now...
return self::send('deleteWebhook', ['delete']);
}
/** /**
* Use this method to edit text and game messages sent by the bot or via the bot (for inline bots). * Use this method to edit text and game messages sent by the bot or via the bot (for inline bots).
* *
......
...@@ -753,18 +753,31 @@ class Telegram ...@@ -753,18 +753,31 @@ class Telegram
} }
/** /**
* Unset Webhook for bot * Deprecated alias for deleteWebhook
*
* This is kept for backwards compatibility!
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function unsetWebhook() public function unsetWebhook()
{ {
$result = Request::setWebhook(); return $this->deleteWebhook();
}
/**
* Delete any assigned webhook
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function deleteWebhook()
{
$result = Request::deleteWebhook();
if (!$result->isOk()) { if (!$result->isOk()) {
throw new TelegramException( throw new TelegramException(
'Webhook was not unset! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription() 'Webhook was not deleted! Error: ' . $result->getErrorCode() . ' ' . $result->getDescription()
); );
} }
......
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