ConversationBuilder

Example

typescript
import * as TalkRn from '@talkjs/react-native';
const me: TalkRn.User = {
id: '123456789',
name: 'Alice',
photoUrl: 'https://demo.talkjs.com/img/alice.jpg',
welcomeMessage: 'Hey there! How are you? :-)',
role: 'default',
};
const other: TalkRn.User = {
id: '432156789',
name: 'Sebastian',
photoUrl: 'https://demo.talkjs.com/img/sebastian.jpg',
welcomeMessage: 'Hey, how can I help? https://google.com',
role: 'default',
};
const conversationId = TalkRn.oneOnOneId(me.id, other.id);
const conversationBuilder = TalkRn.getConversationBuilder(conversationId);
conversationBuilder.setParticipant(me);
conversationBuilder.setParticipant(other, { notify: false });
conversationBuilder.setAttributes({ subject: 'Random conversation' });

Properties

FieldTypeDescription
subject
(optional)
string | nullAn optional conversation subject which will be displayed in the chat header.
photoUrl
(optional)
string | nullAn optional URL to a photo which will be shown as the photo for the conversation.
welcomeMessages
(optional)
string[] | nullMessages which are sent at the beginning of a chat. In this case the messages will appear as system messages.
custom
(optional)
CustomData | nullAllows custom conversation metadata to be stored

Methods

setParticipant

setParticipant(user: User, settings?: ParticipationSettings): void

Sets a participant of the conversation.

This method is idempotent and can be called multiple times.

Parameters

NameTypeDescription
user RequiredUserA User object that identifies the person who is a participant of the conversation. The user is uniquely identified by their id; all other fields (name, photo etc) are overwritten in the TalkJS database each time they change.
settingsParticipationSettingsAn optional setting of participation, can be an initial access right or if user should be notified.

Returns

void

setAttributes

setAttributes(attributes: ConversationAttributes): void

Used to set certain attributes for a specific conversation.

Parameters

NameTypeDescription
attributes RequiredConversationAttributesConversation attributes

Returns

void

sendMessage

sendMessage(text: string, options?: SendMessageOptions): Promise<void>

Sends a text message in a given conversation.

Parameters

NameTypeDescription
text RequiredstringThe message body that is to be sent.
optionsSendMessageOptionsOptional custom data you wish to be associated with the message.

Returns

Promise<void>

Used by


Type Definitions

SendMessageOptions

Example

{
custom: {
location: 'here'
}
}

Properties

FieldTypeDescription
customCustomDataAn object with any custom data that you may wish to associate with this message. The custom data is sent back to you via webhooks and the REST API.

ConversationAttributes

Example

{
subject: 'Our conversation',
photoUrl: 'https://demo.talkjs.com/img/alice.jpg',
welcomeMessages: ['Hello'],
custom: {
store_id: 'g234jl'
}
}

Properties

FieldTypeDescription
subject (optional)string | nullA human-readable subject of the conversation.
Supports formatted links in a Markdown-style syntax. URLs and email addresses are made clickable, and emojis made to work cross-platform.
photoUrl (optional)string | nullThe URL of a photo to be used for this conversation in the TalkJS UI in case there are more than 2 participants (TalkJS shows the photo of the other participant in a 1-on-1 conversation)
welcomeMessages (optional)string[] | nullMessages which are sent at the beginning of a chat. In this case the messages will appear as system messages.
custom (optional)CustomData | nullCustom metadata that is stored with the conversation

ParticipationSettings

Example

{
access: 'Read',
notify: false
}

Properties

FieldTypeDescription
access (optional)"Read" | "ReadWrite"Specifies the participant's access permission for a conversation.
notify (optional)boolean"MentionsOnly"