Documentation

Conversation extends AbstractBaseApi

Class Conversation

Represents a Canvas conversation (internal messaging system). Conversations are user-scoped - they belong to the authenticated user making the API call. All endpoints are at /api/v1/conversations without any context prefix.

Table of Contents

Properties

$audience  : array<string|int, int>|null
$audienceContexts  : array<string, mixed>|null
$avatarUrl  : string|null
$contextName  : string|null
$id  : int|null
$lastMessage  : string|null
$lastMessageAt  : string|null
$messageCount  : int|null
$messages  : array<string|int, array<string, mixed>>|null
$participants  : array<string|int, ConversationParticipant>|null
$private  : bool|null
$properties  : array<string|int, string>|null
$starred  : bool|null
$startAt  : string|null
$subject  : string|null
$subscribed  : bool|null
$visible  : bool|null
$workflowState  : string|null
$apiClient  : HttpClientInterface
$endpoint  : string
$methodAliases  : array<string|int, mixed>
Define method aliases

Methods

__callStatic()  : mixed
Magic method to handle function aliases
__construct()  : mixed
Conversation constructor.
addMessage()  : self
Add a message to an existing conversation
addRecipients()  : self
Add recipients to an existing group conversation
all()  : array<string|int, static>
Get all pages of results
archive()  : self
Archive the conversation
batchUpdate()  : array<string, mixed>
Batch update multiple conversations
create()  : self
Create a new conversation
delete()  : self
Delete a conversation
find()  : self
Get a single conversation
get()  : array<string|int, Conversation>
List conversations for the current user
getRunningBatches()  : array<string|int, array<string, mixed>>
Get running conversation batches
getUnreadCount()  : int
Get unread conversation count
markAllAsRead()  : bool
Mark all conversations as read
markAsRead()  : self
Mark conversation as read
markAsUnread()  : self
Mark conversation as unread
paginate()  : PaginationResult
Get paginated results with metadata
removeMessages()  : self
Remove messages from a conversation
save()  : self
Update a conversation
setApiClient()  : void
Set the API client
star()  : self
Star the conversation
unstar()  : self
Unstar the conversation
castValue()  : DateTime|mixed
Cast a value to the correct type
checkApiClient()  : void
Check if the API client is set, if not, instantiate a new one
convertPaginatedResponseToModels()  : array<string|int, static>
Helper method to convert paginated response data to model instances
createConfiguredHttpClient()  : HttpClient
Create an HttpClient with configured middleware
createPaginationResult()  : PaginationResult
Helper method to create PaginationResult from paginated response
getEndpoint()  : string
Get the API endpoint for this resource
getPaginatedResponse()  : PaginatedResponse
Helper method to get paginated response from API endpoint
populate()  : void
Populate the object with new data Override to handle camelCase properties and participant objects
toDtoArray()  : array<string|int, mixed>
Convert the object to an array

Properties

$audience

public array<string|int, int>|null $audience = null

$audienceContexts

public array<string, mixed>|null $audienceContexts = null

$messages

public array<string|int, array<string, mixed>>|null $messages = null

$properties

public array<string|int, string>|null $properties = null

$endpoint

protected static string $endpoint = '/conversations'

$methodAliases

Define method aliases

protected static array<string|int, mixed> $methodAliases = ['get' => ['fetch', 'list', 'fetchAll'], 'all' => ['fetchAllPages', 'getAll'], 'paginate' => ['getPaginated', 'withPagination', 'fetchPage'], 'find' => ['one', 'getOne']]

Methods

__callStatic()

Magic method to handle function aliases

public static __callStatic(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>
Tags
throws
InvalidArgumentException

__construct()

Conversation constructor.

public __construct([array<string, mixed> $data = [] ]) : mixed

Handles special processing for participants array.

Parameters
$data : array<string, mixed> = []

addMessage()

Add a message to an existing conversation

public addMessage(array<string, mixed>|AddMessageDTO $data) : self
Parameters
$data : array<string, mixed>|AddMessageDTO

Message data

Return values
self

addRecipients()

Add recipients to an existing group conversation

public addRecipients(array<string, mixed>|AddRecipientsDTO $data) : self
Parameters
$data : array<string, mixed>|AddRecipientsDTO

Recipients data

Return values
self

all()

Get all pages of results

public static all([array<string, mixed> $params = [] ]) : array<string|int, static>
Parameters
$params : array<string, mixed> = []

Query parameters

Return values
array<string|int, static>

archive()

Archive the conversation

public archive() : self
Return values
self

batchUpdate()

Batch update multiple conversations

public static batchUpdate(array<string|int, int> $conversationIds, array<string, mixed> $data) : array<string, mixed>
Parameters
$conversationIds : array<string|int, int>

Array of conversation IDs to update

$data : array<string, mixed>

Update data (event: mark_as_read, mark_as_unread, star, unstar, archive, destroy)

Return values
array<string, mixed>

Progress information

delete()

Delete a conversation

public delete() : self
Return values
self

find()

Get a single conversation

public static find(int $id[, array<string, mixed> $params = [] ]) : self
Parameters
$id : int

The conversation ID

$params : array<string, mixed> = []

Optional parameters

  • auto_mark_as_read: Default true
  • scope: unread, starred, archived
  • filter[]: Used for generating "visible" in response
  • filter_mode: and, or, default or
Return values
self

get()

List conversations for the current user

public static get([array<string, mixed> $params = [] ]) : array<string|int, Conversation>
Parameters
$params : array<string, mixed> = []

Optional parameters for filtering and pagination

  • scope: unread, starred, archived, sent
  • filter[]: Filter by courses, groups or users (e.g., "user_123", "course_456")
  • filter_mode: and, or, default or
  • include_all_conversation_ids: Return all conversation IDs
  • include[]: participant_avatars
Return values
array<string|int, Conversation>

Array of Conversation objects

getRunningBatches()

Get running conversation batches

public static getRunningBatches() : array<string|int, array<string, mixed>>
Return values
array<string|int, array<string, mixed>>

Array of batch information

getUnreadCount()

Get unread conversation count

public static getUnreadCount() : int
Return values
int

Unread count

markAllAsRead()

Mark all conversations as read

public static markAllAsRead() : bool
Return values
bool

Success status

markAsRead()

Mark conversation as read

public markAsRead() : self
Return values
self

markAsUnread()

Mark conversation as unread

public markAsUnread() : self
Return values
self

removeMessages()

Remove messages from a conversation

public removeMessages(array<string|int, int> $messageIds) : self
Parameters
$messageIds : array<string|int, int>

Array of message IDs to remove

Return values
self

star()

Star the conversation

public star() : self
Return values
self

unstar()

Unstar the conversation

public unstar() : self
Return values
self

castValue()

Cast a value to the correct type

protected castValue(string $key, mixed $value) : DateTime|mixed
Parameters
$key : string
$value : mixed
Tags
throws
Exception
Return values
DateTime|mixed

checkApiClient()

Check if the API client is set, if not, instantiate a new one

protected static checkApiClient() : void

convertPaginatedResponseToModels()

Helper method to convert paginated response data to model instances

protected static convertPaginatedResponseToModels(PaginatedResponse $paginatedResponse) : array<string|int, static>
Parameters
$paginatedResponse : PaginatedResponse
Return values
array<string|int, static>

getEndpoint()

Get the API endpoint for this resource

protected static getEndpoint() : string
Return values
string

getPaginatedResponse()

Helper method to get paginated response from API endpoint

protected static getPaginatedResponse(string $endpoint[, array<string|int, mixed> $params = [] ]) : PaginatedResponse
Parameters
$endpoint : string

The API endpoint path

$params : array<string|int, mixed> = []

Query parameters for the request

Return values
PaginatedResponse

populate()

Populate the object with new data Override to handle camelCase properties and participant objects

protected populate(array<string, mixed> $data) : void
Parameters
$data : array<string, mixed>

toDtoArray()

Convert the object to an array

protected toDtoArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results