Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F631058
SendtoallCommand.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
SendtoallCommand.php
View Options
<?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
\
Commands
\
AdminCommands
;
use
Longman
\
TelegramBot
\
Commands
\
AdminCommand
;
use
Longman
\
TelegramBot
\
Entities
\
Message
;
use
Longman
\
TelegramBot
\
Entities
\
ServerResponse
;
use
Longman
\
TelegramBot
\
Request
;
/**
* Admin "/sendtoall" command
*/
class
SendtoallCommand
extends
AdminCommand
{
/**
* @var string
*/
protected
$name
=
'sendtoall'
;
/**
* @var string
*/
protected
$description
=
'Send the message to all the user\'s bot'
;
/**
* @var string
*/
protected
$usage
=
'/sendtoall <message to send>'
;
/**
* @var string
*/
protected
$version
=
'1.3.0'
;
/**
* @var bool
*/
protected
$need_mysql
=
true
;
/**
* Execute command
*
* @return boolean
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
execute
(
)
{
$message
=
$this
->
getMessage
(
)
;
$chat_id
=
$message
->
getChat
(
)
->
getId
(
)
;
$text
=
$message
->
getText
(
true
)
;
if
(
$text
===
''
)
{
$text
=
'Write the message to send: /sendtoall <message>'
;
}
else
{
$results
=
Request
::
sendToActiveChats
(
'sendMessage'
,
//callback function to execute (see Request.php methods)
[
'text'
=>
$text
]
,
//Param to evaluate the request
true
,
//Send to groups (group chat)
true
,
//Send to super groups chats (super group chat)
true
,
//Send to users (single chat)
null
,
//'yyyy-mm-dd hh:mm:ss' date range from
null
//'yyyy-mm-dd hh:mm:ss' date range to
)
;
$total
=
0
;
$failed
=
0
;
$text
=
'Message sent to:'
.
PHP_EOL
;
/** @var ServerResponse $result */
foreach
(
$results
as
$result
)
{
$name
=
''
;
$type
=
''
;
if
(
$result
->
isOk
(
)
)
{
$status
=
'✔️'
;
/** @var Message $message */
$message
=
$result
->
getResult
(
)
;
$chat
=
$message
->
getChat
(
)
;
if
(
$chat
->
isPrivateChat
(
)
)
{
$name
=
$chat
->
getFirstName
(
)
;
$type
=
'user'
;
}
else
{
$name
=
$chat
->
getTitle
(
)
;
$type
=
'chat'
;
}
}
else
{
$status
=
'✖️'
;
++
$failed
;
}
++
$total
;
$text
.=
$total
.
') '
.
$status
.
' '
.
$type
.
' '
.
$name
.
PHP_EOL
;
}
$text
.=
'Delivered: '
.
(
$total
-
$failed
)
.
'/'
.
$total
.
PHP_EOL
;
if
(
$total
===
0
)
{
$text
=
'No users or chats found..'
;
}
}
$data
=
[
'chat_id'
=>
$chat_id
,
'text'
=>
$text
,
]
;
return
Request
::
sendMessage
(
$data
)
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Nov 15, 11:02 AM (22 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
141217
Default Alt Text
SendtoallCommand.php (3 KB)
Attached To
Mode
R123 php-telegram-bot
Attached
Detach File
Event Timeline