Chat API
Introduction
ROQ's Chat solution can also be used programmatically using graphQL, or our SDKs. While the primary use-cases are taken care of using the UI components, the GraphQL API may be used to achieve custom functionality.
Mutations
createConversation()
This endpoint is only available from the server side of your application.
You can use this endpoint to create a new chat programmatically, from your server-side code.
roq.asUser("4c94b763-9021-499f-8ea3-b01adcdafe57").createConversation({
conversation: {
title: "ROQ Hackathon planning",
ownerId: "4c94b763-9021-499f-8ea3-b01adcdafe57",
memberIds: [
"4c94b763-9021-499f-8ea3-b01adcdafe57",
"7c15cbe7-21f1-4ff7-b742-ec8604682772",
"cd05a61f-07ca-47e7-abc2-6f0ed9ab645d",
],
isGroup: true,
tags: ["hackathon"],
},
});
Parameter | Type | Description |
---|---|---|
archived | Boolean? | Is the conversation archived or not |
isGroup | Boolean? | Usually set to true when you have 3 or more participants, or when you need to have a named title for a conversation between 2 participants |
memberIds | string[]! | An array of userIds for participants of the conversation |
ownerId | string! | The userId of the owner - i.e usually the creator who has permissions to archive the conversation |
tags | string[]? | An array of strings. These may be used to filter conversations on the UI Components |
title | string! | The title of the conversation, shown at the top of the chat window |
deleteConversation()
Delete a conversation with it's ID
mutation {
deleteConversation(id: "4c94b763-9021-499f-8ea3-b01adcdafe57")
}
assignTagsToConversation()
Assign tags to an existing conversation. These tags can be used to filter conversations on the UI components
mutation {
assignTagsToConversation(
conversationId: "4c94b763-9021-499f-8ea3-b01adcdafe57"
tags: ["hackathon", "hiring"]
)
}
unassignTagsFromConversation()
Remove tags from a conversation.
mutation {
unassignTagsFromConversation(
conversationId: "4c94b763-9021-499f-8ea3-b01adcdafe57"
tags: ["hackathon", "hiring"]
)
}
createMessage()
Send a message to a conversation
mutation {
createMessage(
authorId: "4c94b763-9021-499f-8ea3-b01adcdafe57"
body: "#### Johannes Berge has requested a sample"
conversationId: "7c15cbe7-21f1-4ff7-b742-ec8604682772"
fileId: "7c15cbe7-21f1-4ff7-b742-ec8604682772"
isSystem: false
)
}
Parameter | Type | Description |
---|---|---|
authorId | string! | UserID of the message sender |
body | string! | The body of the message, as a string or markdown |
conversationId | string! | The ID of the conversation into which you want to send the message |
ownerId | string! | The userId of the owner - i.e usually the creator who has permissions to archive the conversation |
fileId | string? | If you want to include an attach a file with the message, specify a fileId |
isSystem | Boolean? | System messages are styled differently in our UI components and can be used to visualize a message from a "bot" or a "system user" |
Queries
messages()
Returns a list of chat messages for a given conversation.
query {
messages(filter: { conversationId: 123 }) {
data {
id
body
fileId
}
}
}
If you don't use the super admin user and the query isn't working for you, then please check if the user has the related permission.