ChatActionSender
in package
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
$action read-only
private
string
$action
= 'typing'
$bot read-only
private
Bot
$bot
$chatId read-only
private
int|string
$chatId
$initialSleep read-only
private
float
$initialSleep
= 0.0
$interval read-only
private
float
$interval
= 5.0
$messageThreadId read-only
private
int|null
$messageThreadId
= null
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
selffindLocation()
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
selfrecordVideo()
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
selfrecordVideoNote()
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
selfrecordVoice()
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
selfscope()
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
Return values
Rstart()
Start the background chat-action loop.
public
start() : ChatActionHandle
Returns a ChatActionHandle whose ChatActionHandle::stop() method must be called to stop the loop. Prefer scope() over manual start/stop.
Return values
ChatActionHandletyping()
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
selfuploadDocument()
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
selfuploadPhoto()
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
selfuploadVideo()
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
selfuploadVideoNote()
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
selfuploadVoice()
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
selfraceDelay()
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>