Chat system
API

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.

mutation {
  createConversation(
    conversation: {
      ownerId: "4c94b763-9021-499f-8ea3-b01adcdafe57"
      isGroup: true
      title: "ROQ Hackathon"
      tags: ["hackathons"]
      memberIds: [
        "4c94b763-9021-499f-8ea3-b01adcdafe57"
        "7c15cbe7-21f1-4ff7-b742-ec8604682772"
        "cd05a61f-07ca-47e7-abc2-6f0ed9ab645d"
      ]
    }
  ) {
    id
    title
    active
    isGroup
  }
}
ParameterTypeDescription
archivedBoolean?Is the conversation archived or not
isGroupBoolean?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
memberIdsstring[]!An array of userIds for participants of the conversation
ownerIdstring!The userId of the owner - i.e usually the creator who has permissions to archive the conversation
tagsstring[]?An array of strings. These may be used to filter conversations on the UI Components
titlestring!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
  )
}
ParameterTypeDescription
authorIdstring!UserID of the message sender
bodystring!The body of the message, as a string or markdown
conversationIdstring!The ID of the conversation into which you want to send the message
ownerIdstring!The userId of the owner - i.e usually the creator who has permissions to archive the conversation
fileIdstring?If you want to include an attach a file with the message, specify a fileId
isSystemBoolean?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.

Image