ConversationBuilder
TypeScript1import * as TalkRn from '@talkjs/react-native';23const me: TalkRn.User = {4 id: '123456789',5 name: 'Alice',7 photoUrl: 'https://talkjs.com/images/avatar-1.jpg',8 welcomeMessage: 'Hey there! How are you? :-)',9};1011const other: TalkRn.User = {12 id: '432156789',13 name: 'Sebastian',15 photoUrl: 'https://talkjs.com/images/avatar-5.jpg',16 welcomeMessage: 'Hey, how can I help? https://google.com',17};1819const conversationId = TalkRn.oneOnOneId(me.id, other.id);20const conversationBuilder = TalkRn.getConversationBuilder(conversationId);2122conversationBuilder.setParticipant(me);23conversationBuilder.setParticipant(other, { notify: false });2425conversationBuilder.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 |
1leave(): Promise<void>
Removes the current user from this conversation.
Promise<boolean>
A promise that resolves with true upon success (indicating that the user has been removed from this conversation), or false when the user did not have the appropriate permissions, as defined in their role. You can find the permissions for a role on the Chat UI page of your TalkJS dashboard. Make sure to select the relevant role from the dropdown selector at the top of the page.
The promise may reject in case of an unexpected error.
1setParticipant(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
1setAttributes(attributes: ConversationAttributes): void
Used to set certain attributes for a specific conversation.
Name | Type | Description |
---|---|---|
attributes Required | ConversationAttributes | Conversation attributes |
void
1sendMessage(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>
1{2 custom: {3 location: 'here'4 }5}
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. |
1{2 subject: 'Our conversation',3 photoUrl: 'https://talkjs.com/images/avatar-1.jpg',4 welcomeMessages: ['Hello'],5 custom: {6 store_id: 'g234jl'7 }8}
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 |
1{2 access: 'Read',3 notify: false4}
Field | Type | Description | |
---|---|---|---|
access (optional) | "Read" | "ReadWrite" | Specifies the participant's access permission for a conversation. | |
notify (optional) | boolean | "MentionsOnly" | Specifies the participant's notification settings. |