Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
dace3e71
Unverified
Commit
dace3e71
authored
Dec 25, 2016
by
Armando Lüscher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new deleteWebhook method to delete a webhook.
Fix some error outputs.
parent
070a08fa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
9 deletions
+37
-9
unset.php
examples/unset.php
+2
-2
Request.php
src/Request.php
+19
-4
Telegram.php
src/Telegram.php
+16
-3
No files found.
examples/unset.php
View file @
dace3e71
...
...
@@ -8,8 +8,8 @@ try {
// Create Telegram API object
$telegram
=
new
Longman\TelegramBot\Telegram
(
$API_KEY
,
$BOT_NAME
);
//
Unset
webhook
$result
=
$telegram
->
unset
Webhook
();
//
Delete
webhook
$result
=
$telegram
->
delete
Webhook
();
if
(
$result
->
isOk
())
{
echo
$result
->
getDescription
();
...
...
src/Request.php
View file @
dace3e71
...
...
@@ -54,6 +54,7 @@ class Request
private
static
$actions
=
[
'getUpdates'
,
'setWebhook'
,
'deleteWebhook'
,
'getMe'
,
'sendMessage'
,
'forwardMessage'
,
...
...
@@ -282,7 +283,7 @@ class Request
{
$fp
=
fopen
(
$file
,
'r'
);
if
(
$fp
===
false
)
{
throw
new
TelegramException
(
'Cannot open
'
.
$file
.
'
for reading'
);
throw
new
TelegramException
(
'Cannot open
"'
.
$file
.
'"
for reading'
);
}
return
$fp
;
...
...
@@ -346,7 +347,7 @@ class Request
private
static
function
ensureValidAction
(
$action
)
{
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
do
{
//Chop off and send the first message
$data
[
'text'
]
=
mb_substr
(
$text
,
0
,
4096
);
$response
=
self
::
send
(
'sendMessage'
,
$data
);
$response
=
self
::
send
(
'sendMessage'
,
$data
);
//Prepare the next message
$text
=
mb_substr
(
$text
,
4096
);
...
...
@@ -807,7 +808,7 @@ class Request
*/
public
static
function
setWebhook
(
$url
=
''
,
array
$data
=
[])
{
$data
=
array_intersect_key
(
$data
,
array_flip
([
$data
=
array_intersect_key
(
$data
,
array_flip
([
'certificate'
,
'max_connections'
,
'allowed_updates'
,
...
...
@@ -821,6 +822,20 @@ class Request
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).
*
...
...
src/Telegram.php
View file @
dace3e71
...
...
@@ -753,18 +753,31 @@ class Telegram
}
/**
* Unset Webhook for bot
* Deprecated alias for deleteWebhook
*
* This is kept for backwards compatibility!
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
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
())
{
throw
new
TelegramException
(
'Webhook was not
unset
! Error: '
.
$result
->
getErrorCode
()
.
' '
.
$result
->
getDescription
()
'Webhook was not
deleted
! Error: '
.
$result
->
getErrorCode
()
.
' '
.
$result
->
getDescription
()
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment