ConversationBuilder
TypeScriptimport * as TalkRn from '@talkjs/react-native';const me: TalkRn.User = {id: '123456789',name: 'Alice',photoUrl: 'https://talkjs.com/images/avatar-1.jpg',welcomeMessage: 'Hey there! How are you? :-)',role: 'default',};const other: TalkRn.User = {id: '432156789',name: 'Sebastian',photoUrl: 'https://talkjs.com/images/avatar-5.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' });
Field | Type | Description |
---|---|---|
string | null | An optional conversation subject which will be displayed in the chat header. | |
string | null | An optional URL to a photo which will be shown as the photo for the conversation. | |
string[] | null | Messages which are sent at the beginning of a chat. In this case the messages will appear as system messages. | |
CustomData | null | Allows custom conversation metadata to be stored |
setParticipant(user: User, settings?: ParticipationSettings): void
Sets a participant of the conversation.
This method is idempotent and can be called multiple times.
Name | Type | Description |
---|---|---|
user Required | User | A 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. |
settings | ParticipationSettings | An optional setting of participation, can be an initial access right or if user should be notified. |
void
setAttributes(attributes: ConversationAttributes): void
Used to set certain attributes for a specific conversation.
Name | Type | Description |
---|---|---|
attributes Required | ConversationAttributes | Conversation attributes |
void
sendMessage(text: string, options?: SendMessageOptions): Promise<void>
Sends a text message in a given conversation.
Name | Type | Description |
---|---|---|
text Required | string | The message body that is to be sent. |
options | SendMessageOptions | Optional custom data you wish to be associated with the message. |
Promise<void>
{custom: {location: 'here'}}
Field | Type | Description |
---|---|---|
custom | CustomData | An 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. |
{subject: 'Our conversation',photoUrl: 'https://talkjs.com/images/avatar-1.jpg',welcomeMessages: ['Hello'],custom: {store_id: 'g234jl'}}
Field | Type | Description |
---|---|---|
subject (optional) | string | null | A 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 | null | The 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[] | null | Messages which are sent at the beginning of a chat. In this case the messages will appear as system messages. |
custom (optional) | CustomData | null | Custom metadata that is stored with the conversation |
{access: 'Read',notify: false}
Field | Type | Description |
---|---|---|
access (optional) | "Read" | "ReadWrite" | Specifies the participant's access permission for a conversation. |
notify (optional) | boolean | "MentionsOnly" |