bootdesk/chat-sdk

TelegramAdapter
in package
implements Adapter, HandlesInteractions, HasAuthorInfo, MustRehydrateAttachments, RequiresAsyncResponse, SupportsMessageMutability

Table of Contents

Interfaces

Adapter
HandlesInteractions
HasAuthorInfo
MustRehydrateAttachments
RequiresAsyncResponse
Marker interface for adapters that expect a quick 200 ACK and should always defer message processing to async execution.
SupportsMessageMutability

Constants

ATTACHMENT_UPLOADS  : mixed = ['audio' => ['field' => 'audio', 'method' => 's...
FILE_UPLOAD_METHODS  : array<string, string> = ['image/webp' => 'sendSticker', 'application/x-...
MULTIPART_FIELDS  : array<string, string> = ['sendPhoto' => 'photo', 'sendAudio' => 'audio'...
NO_CAPTION_METHODS  : mixed = ['sendSticker', 'sendVideoNote']

Properties

$apiUrl  : string
$botToken  : string
$botUserId  : string|null
$emojiResolver  : EmojiResolver
$formatConverter  : TelegramFormatConverter
$httpClient  : ClientInterface
$psrFactory  : Psr17Factory|null
$secretToken  : string|null
$pendingCallbackQueryId  : string|null

Methods

__construct()  : mixed
acknowledgeAction()  : ResponseInterface|null
Acknowledge the action to the platform (e.g. Telegram answerCallbackQuery).
addReaction()  : void
channelIdFromThreadId()  : string
createResponse()  : ResponseInterface|null
decodeThreadId()  : mixed
deleteMessage()  : void
disconnect()  : void
editMessage()  : SentMessage
editThread()  : ThreadInfo
encodeThreadId()  : string
fetchChannelInfo()  : ChannelInfo|null
fetchMedia()  : StreamInterface
fetchMessages()  : FetchResult
fetchThread()  : ThreadInfo
getAuthorInfo()  : Author
getBotUserId()  : string|null
getFormatConverter()  : FormatConverter|null
getName()  : string
getUser()  : UserInfo|null
initialize()  : void
openDM()  : string|null
parseAction()  : Author, actionId: string, value: ?string, threadId: string, messageId: string, userId: string, isBot: bool, isMe: bool, triggerId: ?string, raw: mixed, callbackQueryId: ?string, originId: ?string}|null
parseReaction()  : Author, emoji: string, rawEmoji: string, added: bool, threadId: string, messageId: string, userId: string, raw: mixed, originId: ?string}|null
parseSlashCommand()  : Author, command: string, text: string, userId: string, isBot: bool, isMe: bool, channelId: string, triggerId: ?string, raw: mixed}|null
parseWebhook()  : Message
postMessage()  : SentMessage
rehydrateAttachment()  : Attachment
removeReaction()  : void
startTyping()  : void
stream()  : SentMessage|null
verifyWebhook()  : ResponseInterface|null
apiCall()  : array<string|int, mixed>
apiCallMultipart()  : array<string|int, mixed>
applyEntities()  : string
extractAttachments()  : array<string|int, Attachment>
extractReplyMarkup()  : array<string|int, mixed>|null
getTextContent()  : string

Constants

ATTACHMENT_UPLOADS

private mixed ATTACHMENT_UPLOADS = ['audio' => ['field' => 'audio', 'method' => 'sendAudio'], 'file' => ['field' => 'document', 'method' => 'sendDocument'], 'image' => ['field' => 'photo', 'method' => 'sendPhoto'], 'video' => ['field' => 'video', 'method' => 'sendVideo'], 'sticker' => ['field' => 'sticker', 'method' => 'sendSticker'], 'animation' => ['field' => 'animation', 'method' => 'sendAnimation'], 'video_note' => ['field' => 'video_note', 'method' => 'sendVideoNote']]

FILE_UPLOAD_METHODS

private array<string, string> FILE_UPLOAD_METHODS = ['image/webp' => 'sendSticker', 'application/x-tgsticker' => 'sendSticker']

MIME type → Telegram API method for binary uploads

MULTIPART_FIELDS

private array<string, string> MULTIPART_FIELDS = ['sendPhoto' => 'photo', 'sendAudio' => 'audio', 'sendDocument' => 'document', 'sendVideo' => 'video', 'sendAnimation' => 'animation', 'sendVoice' => 'voice', 'sendVideoNote' => 'video_note', 'sendSticker' => 'sticker']

Telegram API method → multipart field name

NO_CAPTION_METHODS

private mixed NO_CAPTION_METHODS = ['sendSticker', 'sendVideoNote']

Properties

$apiUrl read-only

protected string $apiUrl = 'https://api.telegram.org'

$psrFactory read-only

protected Psr17Factory|null $psrFactory = null

$pendingCallbackQueryId

private string|null $pendingCallbackQueryId = null

Methods

__construct()

public __construct(string $botToken, ClientInterface $httpClient[, string|null $secretToken = null ][, string $apiUrl = 'https://api.telegram.org' ][, Psr17Factory|null $psrFactory = null ][, EmojiResolver|null $emojiResolver = null ]) : mixed
Parameters
$botToken : string
$httpClient : ClientInterface
$secretToken : string|null = null
$apiUrl : string = 'https://api.telegram.org'
$psrFactory : Psr17Factory|null = null
$emojiResolver : EmojiResolver|null = null

acknowledgeAction()

Acknowledge the action to the platform (e.g. Telegram answerCallbackQuery).

public acknowledgeAction(string|null $callbackQueryId) : ResponseInterface|null
Parameters
$callbackQueryId : string|null
Return values
ResponseInterface|null

addReaction()

public addReaction(string $threadId, string $messageId, string $emoji) : void
Parameters
$threadId : string
$messageId : string
$emoji : string

channelIdFromThreadId()

public channelIdFromThreadId(string $threadId) : string
Parameters
$threadId : string
Return values
string

createResponse()

public createResponse() : ResponseInterface|null
Return values
ResponseInterface|null

decodeThreadId()

public decodeThreadId(string $threadId) : mixed
Parameters
$threadId : string

deleteMessage()

public deleteMessage(string $threadId, string $messageId) : void
Parameters
$threadId : string
$messageId : string

encodeThreadId()

public encodeThreadId(mixed $platformData) : string
Parameters
$platformData : mixed
Return values
string

getBotUserId()

public getBotUserId() : string|null
Return values
string|null

openDM()

public openDM(string $userId) : string|null
Parameters
$userId : string
Return values
string|null

parseAction()

public parseAction(ServerRequestInterface $request) : Author, actionId: string, value: ?string, threadId: string, messageId: string, userId: string, isBot: bool, isMe: bool, triggerId: ?string, raw: mixed, callbackQueryId: ?string, originId: ?string}|null
Parameters
$request : ServerRequestInterface
Return values
Author, actionId: string, value: ?string, threadId: string, messageId: string, userId: string, isBot: bool, isMe: bool, triggerId: ?string, raw: mixed, callbackQueryId: ?string, originId: ?string}|null

parseReaction()

public parseReaction(ServerRequestInterface $request) : Author, emoji: string, rawEmoji: string, added: bool, threadId: string, messageId: string, userId: string, raw: mixed, originId: ?string}|null
Parameters
$request : ServerRequestInterface
Return values
Author, emoji: string, rawEmoji: string, added: bool, threadId: string, messageId: string, userId: string, raw: mixed, originId: ?string}|null

parseSlashCommand()

public parseSlashCommand(ServerRequestInterface $request) : Author, command: string, text: string, userId: string, isBot: bool, isMe: bool, channelId: string, triggerId: ?string, raw: mixed}|null
Parameters
$request : ServerRequestInterface
Return values
Author, command: string, text: string, userId: string, isBot: bool, isMe: bool, channelId: string, triggerId: ?string, raw: mixed}|null

parseWebhook()

public parseWebhook(ServerRequestInterface $request) : Message
Parameters
$request : ServerRequestInterface
Return values
Message

removeReaction()

public removeReaction(string $threadId, string $messageId, string $emoji) : void
Parameters
$threadId : string
$messageId : string
$emoji : string

startTyping()

public startTyping(string $threadId) : void
Parameters
$threadId : string

stream()

public stream(string $threadId, iterable<string|int, mixed> $textStream[, array<string|int, mixed> $options = [] ]) : SentMessage|null
Parameters
$threadId : string
$textStream : iterable<string|int, mixed>
$options : array<string|int, mixed> = []
Return values
SentMessage|null

verifyWebhook()

public verifyWebhook(ServerRequestInterface $request) : ResponseInterface|null
Parameters
$request : ServerRequestInterface
Return values
ResponseInterface|null

apiCall()

protected apiCall(string $method[, array<string|int, mixed> $params = [] ][, string $httpMethod = 'POST' ][, string|null $overrideUrl = null ][, bool $returnStream = false ]) : array<string|int, mixed>
Parameters
$method : string
$params : array<string|int, mixed> = []
$httpMethod : string = 'POST'
$overrideUrl : string|null = null
$returnStream : bool = false
Return values
array<string|int, mixed>

apiCallMultipart()

protected apiCallMultipart(string $method, array<string|int, mixed> $params[, FileUpload|null $file = null ]) : array<string|int, mixed>
Parameters
$method : string
$params : array<string|int, mixed>
$file : FileUpload|null = null
Return values
array<string|int, mixed>

applyEntities()

protected applyEntities(string $text, array<string|int, mixed> $entities) : string
Parameters
$text : string
$entities : array<string|int, mixed>
Return values
string

extractAttachments()

protected extractAttachments(array<string|int, mixed> $tgMessage) : array<string|int, Attachment>
Parameters
$tgMessage : array<string|int, mixed>
Return values
array<string|int, Attachment>
On this page

Search results