phpbotgram

ChatActionSender
in package

FinalYes

Periodically emits a `sendChatAction` call to Telegram while a long operation is running, giving the user visual feedback that the bot is active.

Mirrors upstream aiogram.utils.chat_action.ChatActionSender.

Usage (explicit):

$handle = $sender->start();
try {
    // long operation
} finally {
    $handle->stop();
}

Usage (scoped helper):

$result = $sender->scope(function () {
    return doLongWork();
});

Or via static factories:

ChatActionSender::typing(bot: $bot, chatId: 123)->scope(fn () => longOp());

Table of Contents

Properties

$action  : string
$bot  : Bot
$chatId  : int|string
$initialSleep  : float
$interval  : float
$messageThreadId  : int|null

Methods

__construct()  : mixed
chooseSticker()  : self
findLocation()  : self
recordVideo()  : self
recordVideoNote()  : self
recordVoice()  : self
scope()  : R
Run `$body` while the chat-action loop is active. Stops the loop when `$body` returns or throws.
start()  : ChatActionHandle
Start the background chat-action loop.
typing()  : self
uploadDocument()  : self
uploadPhoto()  : self
uploadVideo()  : self
uploadVideoNote()  : self
uploadVoice()  : self
raceDelay()  : void
Race a delay against the close-future. Returns when either the delay elapses or the close signal fires — whichever comes first.

Properties

Methods

__construct()

public __construct(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, string $action = 'typing' ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : mixed
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$action : string = 'typing'
$interval : float = 5.0
$initialSleep : float = 0.0

chooseSticker()

public static chooseSticker(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

findLocation()

public static findLocation(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

recordVideo()

public static recordVideo(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

recordVideoNote()

public static recordVideoNote(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

recordVoice()

public static recordVoice(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

scope()

Run `$body` while the chat-action loop is active. Stops the loop when `$body` returns or throws.

public scope(callable(): R $body) : R
Parameters
$body : callable(): R
Tags
template
Return values
R

typing()

public static typing(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

uploadDocument()

public static uploadDocument(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

uploadPhoto()

public static uploadPhoto(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

uploadVideo()

public static uploadVideo(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

uploadVideoNote()

public static uploadVideoNote(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

uploadVoice()

public static uploadVoice(Bot $bot, int|string $chatId[, int|null $messageThreadId = null ][, float $interval = 5.0 ][, float $initialSleep = 0.0 ]) : self
Parameters
$bot : Bot
$chatId : int|string
$messageThreadId : int|null = null
$interval : float = 5.0
$initialSleep : float = 0.0
Return values
self

raceDelay()

Race a delay against the close-future. Returns when either the delay elapses or the close signal fires — whichever comes first.

private static raceDelay(float $seconds, Future<string|int, null> $closeFuture) : void

Uses DeferredCancellation to cancel the underlying event-loop timer when the close-future wins, preventing orphaned timers from accumulating when many senders are stopped early.

Parameters
$seconds : float
$closeFuture : Future<string|int, null>
On this page

Search results