TelegramPHP Documentation

UserRepository extends AbstractRepository
in package

The users this client has seen in an update - `$telegram->users`.

The Bot API has no "get user" call: a bot only ever learns about a user by being told about them. fetch() therefore resolves a membership - getChatMember against a chat the bot is in - and caches the user it carries; get() answers from what updates have already brought in.

Tags
extends
author

Valithor Obsidion valithor@valgorithms.com

Table of Contents

Properties

$discrim  : string
The attribute that identifies a row.
$items  : Collection<string|int, TPart>
$part  : string
The part class this repository holds.
$telegram  : Telegram

Methods

__construct()  : mixed
all()  : Collection<string|int, TPart>
cache()  : TPart
Remembers a part, or merges it into the one already held under that id.
clear()  : void
count()  : int
fetch()  : PromiseInterface<string|int, User>
Not supported: the Bot API exposes no way to look a user up by id alone.
fetchMember()  : PromiseInterface<string|int, ChatMember>
Looks the user up as a member of a chat the bot is in, caching the {@see User} the membership carries.
fetchOrGet()  : PromiseInterface<string|int, TPart>
The cached part if there is one, otherwise a fresh copy from Telegram.
get()  : TPart|null
The cached part with this id, if it has been seen.
getIterator()  : Traversable
has()  : bool
normalise()  : int|string
Telegram ids are integers, but they arrive as strings often enough - out of a config file, off a command argument - that a lookup has to accept both.

Properties

$part

The part class this repository holds.

protected string $part = \Telegram\Parts\User::class

Methods

all()

public all() : Collection<string|int, TPart>
Return values
Collection<string|int, TPart>

cache()

Remembers a part, or merges it into the one already held under that id.

public cache(TPart $part) : TPart
Parameters
$part : TPart
Return values
TPart

The cached part - the merged one when an entry already existed.

fetch()

Not supported: the Bot API exposes no way to look a user up by id alone.

public fetch(int|string $id) : PromiseInterface<string|int, User>

Use fetchMember() with a chat the bot shares with them, or read the user off the update that mentioned them.

Parameters
$id : int|string
Tags
throws
BadMethodCallException

Always.

Return values
PromiseInterface<string|int, User>

fetchMember()

Looks the user up as a member of a chat the bot is in, caching the {@see User} the membership carries.

public fetchMember(int|string $chatId, int $userId) : PromiseInterface<string|int, ChatMember>
Parameters
$chatId : int|string
$userId : int
Return values
PromiseInterface<string|int, ChatMember>

fetchOrGet()

The cached part if there is one, otherwise a fresh copy from Telegram.

public fetchOrGet(int|string $id) : PromiseInterface<string|int, TPart>
Parameters
$id : int|string
Return values
PromiseInterface<string|int, TPart>

get()

The cached part with this id, if it has been seen.

public get(int|string $id) : TPart|null
Parameters
$id : int|string
Return values
TPart|null

has()

public has(int|string $id) : bool
Parameters
$id : int|string
Return values
bool

normalise()

Telegram ids are integers, but they arrive as strings often enough - out of a config file, off a command argument - that a lookup has to accept both.

protected static normalise(int|string $id) : int|string

A @channelusername is left alone; it is not an id at all.

Parameters
$id : int|string
Return values
int|string
On this page

Search results