API reference

Written By Stanislas

Last updated 16 days ago


Complete reference for all GraphQL types, queries, mutations, and subscriptions in the Swiftask Public Bot API. Use this as a lookup guide when building your integration.

Overview

This reference documents every GraphQL type, input type, query, mutation, and subscription available in the Swiftask API. Each entry includes the GraphQL schema, field descriptions, and common usage examples. Use this guide alongside the practical examples in other guides.

The API is organized into three main categories: data types (what the API returns), input types (what you send to the API), and operations (queries, mutations, and subscriptions).


GraphQL types

TodoChatMessage

Represents a single message in a chat session.

GraphQL Type:

type TodoChatMessage {
  id: Int!
  message: String
  createdAt: DateTime!
  updatedAt: DateTime!
  sessionId: Int!
  sentBy: User!
  isBotReply: Boolean
  files: [File]
  parentMessageId: Int
}

Field descriptions:

Field

Type

Description

id

Int

Unique message identifier

message

String

Message text content

createdAt

DateTime

Timestamp when message was created

updatedAt

DateTime

Timestamp of last update

sessionId

Int

ID of the session this message belongs to

sentBy

User

User who sent the message (includes id, firstName, lastName)

isBotReply

Boolean

Whether this is a bot response (true) or user message (false)

files

[File]

Array of attached files (if any)

parentMessageId

Int

ID of parent message (for threaded replies)

Example usage:

const message = {
  id: 12345,
  message: 'What is your pricing?',
  createdAt: '2024-01-29T19:50:13.631Z',
  updatedAt: '2024-01-29T19:50:13.631Z',
  sessionId: 67890,
  sentBy: {
    id: 1,
    firstName: 'John',
    lastName: 'Doe',
  },
  isBotReply: false,
  files: null,
  parentMessageId: null,
};

TodoChatSession

Represents a chat session containing multiple messages.

GraphQL Type:

type TodoChatSession {
  id: Int!
  title: String
  createdAt: DateTime!
  updatedAt: DateTime!
  todoId: Int!
  defaultBotId: Int
  messages: [TodoChatMessage]
  uiLayout: String
}

Field descriptions:

Field

Type

Description

id

Int

Unique session identifier

title

String

Session title (user-friendly name)

createdAt

DateTime

Timestamp when session was created

updatedAt

DateTime

Timestamp of last update

todoId

Int

Associated todo/container ID

defaultBotId

Int

Default bot/agent for this session

messages

[TodoChatMessage]

Array of all messages in this session

uiLayout

String

UI layout preference ("DEFAULT" or "COMPACT")

Example usage:

const session = {
  id: 67890,
  title: 'Customer Support',
  createdAt: '2024-01-29T19:50:13.631Z',
  updatedAt: '2024-01-29T20:15:45.123Z',
  todoId: 12345,
  defaultBotId: 789,
  messages: [
    { id: 1, message: 'Hello', isBotReply: false },
    { id: 2, message: 'Hi there!', isBotReply: true },
  ],
  uiLayout: 'DEFAULT',
};

ChatStreamMessage

Represents a chunk of a streaming message.

GraphQL Type:

type ChatStreamMessage {
  messageChunk: String!
  userId: Int!
  id: Int!
  botId: Int!
  botResponseMessageId: Int!
  isStoppable: Boolean!
}

Field descriptions:

Field

Type

Description

messageChunk

String

Text chunk to append to the growing message

userId

Int

ID of the user receiving the stream

id

Int

Stream message ID

botId

Int

ID of the bot generating the response

botResponseMessageId

Int

ID of the complete response message (when done)

isStoppable

Boolean

Whether generation can be stopped

Example usage:

// Each subscription event looks like this:
const streamChunk = {
  messageChunk: 'Hello, ',
  userId: 1,
  id: 54321,
  botId: 789,
  botResponseMessageId: 12345,
  isStoppable: true,
};

// Next chunk:
const nextChunk = {
  messageChunk: 'how can I help?',
  userId: 1,
  id: 54322,
  botId: 789,
  botResponseMessageId: 12345,
  isStoppable: true,
};

AgentToolCall

Represents an agent tool call event.

GraphQL Type:

type AgentToolCall {
  tool: String!
  toolImage: String
  botId: Int!
  id: Int!
  status: String!
}

Field descriptions:

Field

Type

Description

tool

String

Name of the tool being used (e.g., "web_search", "calculator")

toolImage

String

Icon or image URL for the tool

botId

Int

ID of the bot using the tool

id

Int

Tool call event ID

status

String

Current status: "START", "END", or "ERROR"

Common tool names:

  • web_search β€” Web searching

  • calculator β€” Mathematical calculations

  • knowledge_base β€” Knowledge base lookup

  • api_call β€” External API calls

  • database_query β€” Database queries

  • file_search β€” File searching

Example usage:

const toolCall = {
  tool: 'web_search',
  toolImage: 'https://...',
  botId: 789,
  id: 99999,
  status: 'START',
};

// Later:
const toolEnd = {
  tool: 'web_search',
  toolImage: 'https://...',
  botId: 789,
  id: 100000,
  status: 'END',
};

SyncBotResponse

Response from a synchronous bot request.

GraphQL Type:

type SyncBotResponse {
  text: String!
  botId: Int
  botSlug: String
  isBotError: Boolean
  sessionId: Int
  files: JSON
  sourceMetadatas: JSON
  sources: JSON
  responseJson: JSON
  jobId: String
}

Field descriptions:

Field

Type

Description

text

String

Complete response text

botId

Int

ID of the responding bot

botSlug

String

Slug/identifier of the responding bot

isBotError

Boolean

Whether an error occurred during processing

sessionId

Int

Session ID where response was generated

files

JSON

Attached files (if any)

sourceMetadatas

JSON

Metadata about sources used

sources

JSON

Sources used to generate the response

responseJson

JSON

Full response data as JSON

jobId

String

Background job ID (if applicable)

Example usage:

const response = {
  text: 'The capital of France is Paris.',
  botId: 789,
  botSlug: 'knowledge-bot',
  isBotError: false,
  sessionId: 67890,
  sources: [
    { title: 'Wikipedia', url: 'https://...' },
    { title: 'Britannica', url: 'https://...' },
  ],
  sourceMetadatas: { count: 2 },
  files: null,
  responseJson: { answer: 'Paris', confidence: 0.99 },
  jobId: 'job_123456',
};

User

Represents a user in the system.

GraphQL Type:

type User {
  id: Int!
  firstName: String
  lastName: String
  email: String
}

Field descriptions:

Field

Type

Description

id

Int

Unique user identifier

firstName

String

User's first name

lastName

String

User's last name

email

String

User's email address

Input types

NewMessageInput

Input for sending a new message.

GraphQL Input Type:

input NewMessageInput {
  message: String
  todoChatId: Int
  fileIds: [Int]
  mentionedUserId: Int
  mentionedUserIds: [Int]
  mentionedBotId: Int
  parentMessageId: Int
  botPromptId: Int
  sessionId: Int
  command: String
  extraConfig: JSON
  isForAiReply: Boolean
}

Field descriptions:

Field

Type

Required

Description

message

String

No

Message text to send

sessionId

Int

Yes

Session ID (required)

isForAiReply

Boolean

No

If true, triggers AI response

fileIds

[Int]

No

Array of file IDs to attach

mentionedUserId

Int

No

Single user to mention

mentionedUserIds

[Int]

No

Multiple users to mention

mentionedBotId

Int

No

Bot to mention/invoke

parentMessageId

Int

No

Parent message ID (for threading)

botPromptId

Int

No

Predefined prompt to use

command

String

No

Special command for the agent

extraConfig

JSON

No

Additional configuration

todoChatId

Int

No

(Deprecated) Use sessionId instead

Example usage:

const messageInput = {
  message: 'What is the weather?',
  sessionId: 67890,
  isForAiReply: true,
};

const messageWithFiles = {
  message: 'Analyze these documents',
  sessionId: 67890,
  fileIds: [101, 102, 103],
  isForAiReply: true,
};

const threadedReply = {
  message: 'Can you elaborate?',
  sessionId: 67890,
  parentMessageId: 12345,
  isForAiReply: true,
};

TodoChatSessionInput

Input for creating or updating a session.

GraphQL Input Type:

input TodoChatSessionInput {
  title: String
  todoChatId: Int
  todoId: Int
  createFromChatAsDataSourceId: Int
  defaultBotId: Int
  fromBotPromptId: Int
  toogleChatGptVersion: Boolean
  autoReplyLMM: Boolean
  chatCollectionId: Int
  uiLayout: String
}

Field descriptions:

Field

Type

Required

Description

title

String

No

Session title (max 200 characters)

todoId

Int

Yes

Todo/container ID (required for creation)

defaultBotId

Int

No

Default bot for this session

uiLayout

String

No

UI layout ("DEFAULT" or "COMPACT")

createFromChatAsDataSourceId

Int

No

Create session from datasource

fromBotPromptId

Int

No

Initialize from prompt

chatCollectionId

Int

No

Associate with collection

autoReplyLMM

Boolean

No

Enable auto-reply

toogleChatGptVersion

Boolean

No

(Deprecated) Toggle ChatGPT version

todoChatId

Int

No

(Deprecated) Use todoId instead

Example usage:

const basicSession = {
  title: 'Support Chat',
  todoId: 12345,
};

const sessionWithBot = {
  title: 'Sales Inquiry',
  todoId: 12345,
  defaultBotId: 789,
};

const compactSession = {
  title: 'Quick Chat',
  todoId: 12345,
  uiLayout: 'COMPACT',
};

BotCustomConfigInput

Input for custom bot configuration.

GraphQL Input Type:

input BotCustomConfigInput {
  botId: Int!
  sessionId: Int
  model: String
  temperature: Float
}

Field descriptions:

Field

Type

Required

Description

botId

Int

Yes

Bot ID (required)

sessionId

Int

No

Session ID (if session-specific)

model

String

No

LLM model name (e.g., "gpt-4", "claude-3")

temperature

Float

No

Temperature (0-1, controls randomness)

Example usage:

const botConfig = {
  botId: 123,
  sessionId: 67890,
  model: 'gpt-4',
  temperature: 0.7,
};

Queries

getTodoChatSessions

Get a paginated list of chat sessions.

GraphQL Query:

query GetTodoChatSessions($todoId: Float!, $limit: Int, $offset: Int) {
  getTodoChatSessions(todoId: $todoId, limit: $limit, offset: $offset) {
    sessions {
      id
      title
      createdAt
      updatedAt
      defaultBotId
    }
    totalCount
  }
}

Parameters:

Parameter

Type

Required

Default

Description

todoId

Float

Yes

β€”

Todo ID to fetch sessions for

limit

Int

No

20

Number of sessions per page

offset

Int

No

0

Pagination offset

Returns: Object with sessions array and totalCount

Example:

const result = await client.query({
  query: gql`
    query GetTodoChatSessions($todoId: Float!, $limit: Int, $offset: Int) {
      getTodoChatSessions(todoId: $todoId, limit: $limit, offset: $offset) {
        sessions {
          id
          title
          createdAt
        }
        totalCount
      }
    }
  `,
  variables: { todoId: 12345, limit: 20, offset: 0 },
});

console.log(`Total sessions: ${result.data.getTodoChatSessions.totalCount}`);

getOneTodoChatSession

Get details of a specific session including all messages.

GraphQL Query:

query GetOneTodoChatSession($sessionId: Float!) {
  getOneTodoChatSession(sessionId: $sessionId) {
    id
    title
    createdAt
    updatedAt
    defaultBotId
    todoId
    messages {
      id
      message
      createdAt
      sentBy {
        id
        firstName
      }
      isBotReply
    }
  }
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID to retrieve

Returns: Complete TodoChatSession object with messages

getOrCreateUserStartTodoChatSession

Get or create the default starter session for a user.

GraphQL Query:

query GetOrCreateUserStartTodoChatSession($botSlug: String) {
  getOrCreateUserStartTodoChatSession(botSlug: $botSlug) {
    id
    title
    defaultBotId
    todoId
  }
}

Parameters:

Parameter

Type

Required

Description

botSlug

String

No

Bot slug (optional)

Returns: TodoChatSession object (created if doesn't exist)

getSearchTodoChatSessions

Search chat sessions by query string.

GraphQL Query:

query GetSearchTodoChatSessions($todoId: Float!, $searchQuery: String) {
  getSearchTodoChatSessions(todoId: $todoId, searchQuery: $searchQuery) {
    id
    title
    createdAt
  }
}

Parameters:

Parameter

Type

Required

Description

todoId

Float

Yes

Todo ID to search within

searchQuery

String

No

Search term

Returns: Array of matching TodoChatSession objects

getSpeechFromText

Get audio URL for text-to-speech conversion.

GraphQL Query:

query GetSpeechFromText($messageId: Float!) {
  getSpeechFromText(messageId: $messageId)
}

Parameters:

Parameter

Type

Required

Description

messageId

Float

Yes

Message ID to convert

Returns: Audio URL string

Mutations

sendNewMessage

Send a new message and trigger streaming response.

GraphQL Mutation:

mutation SendNewMessage($newMessageData: NewMessageInput!) {
  sendNewMessage(newMessageData: $newMessageData) {
    id
    message
    createdAt
    sessionId
    sentBy {
      id
      firstName
      lastName
    }
    isBotReply
  }
}

Parameters:

Parameter

Type

Required

Description

newMessageData

NewMessageInput

Yes

Message input object

Returns: TodoChatMessage object

Example:

const { data } = await client.mutate({
  mutation: gql`
    mutation SendNewMessage($newMessageData: NewMessageInput!) {
      sendNewMessage(newMessageData: $newMessageData) {
        id
        message
      }
    }
  `,
  variables: {
    newMessageData: {
      message: 'Hello!',
      sessionId: 67890,
      isForAiReply: true,
    },
  },
});

syncBotRequest

Send message and get complete response (non-streaming).

GraphQL Mutation:

mutation SyncBotRequest($newMessageData: NewMessageInput!) {
  syncBotRequest(newMessageData: $newMessageData) {
    text
    botId
    botSlug
    isBotError
    sessionId
    files
    sourceMetadatas
    sources
    responseJson
    jobId
  }
}

Parameters:

Parameter

Type

Required

Description

newMessageData

NewMessageInput

Yes

Message input object

Returns: SyncBotResponse object

regenerateResponse

Regenerate the bot's response for a message.

GraphQL Mutation:

mutation RegenerateResponse($messageId: Float!) {
  regenerateResponse(messageId: $messageId) {
    id
    message
    createdAt
  }
}

Parameters:

Parameter

Type

Required

Description

messageId

Float

Yes

Message ID to regenerate

Returns: TodoChatMessage object (new response)

stopAIResponse

Stop ongoing AI response generation.

GraphQL Mutation:

mutation StopAIResponse($sessionId: Float!, $botId: Float!) {
  stopAIResponse(sessionId: $sessionId, botId: $botId)
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID

botId

Float

Yes

Bot ID

Returns: Boolean (true if stopped successfully)

retryBotMessage

Retry sending a message that failed.

GraphQL Mutation:

mutation RetryBotMessage($sessionId: Float!) {
  retryBotMessage(sessionId: $sessionId)
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID

Returns: Boolean (true if retry succeeded)

createTodoChatSession

Create a new chat session.

GraphQL Mutation:

mutation CreateTodoChatSession($data: TodoChatSessionInput!) {
  createTodoChatSession(data: $data) {
    id
    title
    createdAt
    defaultBotId
    todoId
  }
}

Parameters:

Parameter

Type

Required

Description

data

TodoChatSessionInput

Yes

Session input object

Returns: TodoChatSession object

updateTodoChatSession

Update an existing session.

GraphQL Mutation:

mutation UpdateTodoChatSession($data: TodoChatSessionInput!, $id: Float!) {
  updateTodoChatSession(data: $data, id: $id) {
    id
    title
    updatedAt
  }
}

Parameters:

Parameter

Type

Required

Description

data

TodoChatSessionInput

Yes

Updated session data

id

Float

Yes

Session ID to update

Returns: TodoChatSession object

deleteTodoChatSession

Delete a single session.

GraphQL Mutation:

mutation DeleteTodoChatSession($id: Float!) {
  deleteTodoChatSession(id: $id) {
    id
  }
}

Parameters:

Parameter

Type

Required

Description

id

Float

Yes

Session ID to delete

Returns: TodoChatSession object

deleteManyTodoChatSession

Delete multiple sessions in one operation.

GraphQL Mutation:

mutation DeleteManyTodoChatSession($ids: [Int!]!) {
  deleteManyTodoChatSession(ids: $ids)
}

Parameters:

Parameter

Type

Required

Description

ids

[Int]

Yes

Array of session IDs to delete

Returns: Number of deleted sessions

updateTodoChatSessionCustomBotConfig

Update bot configuration for a session.

GraphQL Mutation:

mutation UpdateCustomBotConfig($data: BotCustomConfigInput!) {
  updateTodoChatSessionCustomBotConfig(data: $data) {
    id
  }
}

Parameters:

Parameter

Type

Required

Description

data

BotCustomConfigInput

Yes

Bot config input object

Returns: TodoChatSession object

Subscriptions

onMessageStream

Subscribe to real-time message streaming.

GraphQL Subscription:

subscription OnMessageStream($sessionId: Float!) {
  onMessageStream(sessionId: $sessionId) {
    messageChunk
    userId
    id
    botId
    botResponseMessageId
    isStoppable
  }
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID to subscribe to

Emits: ChatStreamMessage objects

newMessage

Subscribe to new complete messages.

GraphQL Subscription:

subscription NewMessage($sessionId: Float!) {
  newMessage(sessionId: $sessionId) {
    id
    message
    createdAt
    sentBy {
      firstName
    }
    isBotReply
  }
} 

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID to subscribe to

Emits: TodoChatMessage objects

newIntermediateMessage

Subscribe to intermediate messages (thinking steps).

GraphQL Subscription:

subscription NewIntermediateMessage($sessionId: Float!) {
  newIntermediateMessage(sessionId: $sessionId) {
    id
    message
    createdAt
    isBotReply
  }
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID to subscribe to

Emits: TodoChatMessage objects

onAgentToolCall

Subscribe to agent tool call events.

GraphQL Subscription:

subscription OnAgentToolCall($sessionId: Float!) {
  onAgentToolCall(sessionId: $sessionId) {
    tool
    toolImage
    botId
    id
    status
  }
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID to subscribe to

Emits: AgentToolCall objects

userTyping

Subscribe to user typing events.

GraphQL Subscription:

subscription UserTyping($sessionId: Float!) {
  userTyping(sessionId: $sessionId) {
    id
    firstName
    lastName
  }
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID to subscribe to

Emits: User objects

botAnalyzingDatasources

Subscribe to bot analyzing datasource events.

GraphQL Subscription:

subscription BotAnalyzingDatasources($sessionId: Float!) {
  botAnalyzingDatasources(sessionId: $sessionId) {
    id
    firstName
  }
}

Parameters:

Parameter

Type

Required

Description

sessionId

Float

Yes

Session ID to subscribe to

Emits: User objects

API endpoints

REST endpoints

Endpoint

Method

Purpose

/public/widget-bot/:clientToken

GET

Authentication and configuration

Base URL: https://graphql.swiftask.ai

GraphQL endpoints

Endpoint

Protocol

Purpose

/graphql

HTTP

Queries and mutations

/graphql

WebSocket

Subscriptions

Base URL: https://graphql.swiftask.ai (HTTP) or wss://graphql.swiftask.ai (WebSocket)

Required headers

All GraphQL requests must include these headers:

Header

Value

Purpose

authorization

Bearer {accessToken}

Authentication

x-workspace-id

{workspaceId}

Workspace routing

x-client

widget

Client identification

WebSocket connections use connectionParams instead of headers:

connectionParams: {
  authorization: `Bearer ${accessToken}`,
  workspaceId: workspaceId,
}

Common patterns

Pagination

When listing sessions, use limit and offset for pagination:

// Get first 20 sessions
const page1 = await client.query({
  variables: { todoId, limit: 20, offset: 0 },
});

// Get next 20 sessions
const page2 = await client.query({
  variables: { todoId, limit: 20, offset: 20 },
});

// Get total count
const totalCount = page1.data.getTodoChatSessions.totalCount;
const totalPages = Math.ceil(totalCount / 20);Error handling

All operations can fail. Handle errors consistently:

try {
  const { data } = await client.mutate({ mutation });
  return data;
} catch (error) {
  if (error.graphQLErrors?.length > 0) {
    console.error('GraphQL Error:', error.graphQLErrors[0].message);
  } else if (error.networkError) {
    console.error('Network Error:', error.networkError);
  } else {
    console.error('Unknown Error:', error);
  }
  throw error;
}

Null handling

Some fields are optional. Always check for null:

const message = data.sendNewMessage;
if (message.files) {
  // Process files
}

if (message.parentMessageId) {
  // This is a threaded reply
}