interface ChatService {
    addCommandToChannelType(
        channelTypeName: TRIP,
        commandName: string,
    ): Promise<boolean>;
    addMembersToChannel(
        channelId: string,
        channelTypeName: TRIP,
        users: ChannelMember[],
    ): Promise<Channel>;
    addModeratorsToChannel(
        channelId: string,
        channelTypeName: TRIP,
        moderators: string[],
    ): Promise<Channel>;
    createChannel(
        id: string,
        name: string,
        type: TRIP,
        createdById: string,
        imageUrl?: string,
    ): Promise<Channel>;
    createCommand(command: Command): Promise<boolean>;
    createToken(userId: string): string;
    createUser(
        id: string,
        name: string,
        role?: ChannelMemberRole,
    ): Promise<ChatUser>;
    deleteCommand(name: string): Promise<void>;
    getChannel(
        channelId: string,
        channelTypeName: TRIP,
    ): Promise<null | Channel>;
    getUser(id: string): Promise<null | ChatUser>;
    ping(): Promise<void>;
    removeUsersFromChat(
        channelId: string,
        channelTypeName: TRIP,
        userIds: string[],
    ): Promise<Channel>;
    sendMessageToChannel(
        channelId: string,
        channelTypeName: TRIP,
        senderId: string,
        message: ChatMessage,
    ): Promise<boolean>;
    updateChannel(
        id: string,
        channelTypeName: TRIP,
        channelUpdate: ChannelUpdate,
    ): Promise<Channel>;
    updateCommand(name: string, options: CommandUpdate): Promise<boolean>;
    updateUser(id: string, userUpdate: UserUpdate): Promise<ChatUser>;
}

Methods

  • Adds a command to a specified channel type.

    Parameters

    • channelTypeName: TRIP

      The name of the channel to which the command will be added.

    • commandName: string

      The name of the command to be added.

    Returns Promise<boolean>

    • Returns a promise that resolves to true if the command was successfully added, or was already present. Otherwise, resolves to false if there was an error during the process.
    const success = await addCommandToChannelType('trip', 'itinerary');
    console.log(success); // true or false
  • Adds users to a channel using the chat provider.

    Parameters

    • channelId: string

      The ID of the channel to which the user will be added.

    • channelTypeName: TRIP

      The type of the channel to which the user will be added.

    • users: ChannelMember[]

      The users to add to the channel. This can be an array of user IDs or an array of objects containing the user ID and the channel role.

    Returns Promise<Channel>

  • Adds moderators to a channel using the chat provider.

    Parameters

    • channelId: string

      The ID of the channel to which the moderators will be added.

    • channelTypeName: TRIP

      The type of the channel to which the moderators will be added.

    • moderators: string[]

      The moderators to add to the channel.

    Returns Promise<Channel>

  • Creates a channel using the chat provider.

    Parameters

    • id: string

      The ID of the channel to create.

    • name: string

      The name of the channel to create.

    • type: TRIP

      The type of the channel to create.

    • createdById: string

      The ID of the user who created the channel.

    • OptionalimageUrl: string

      The URL of the image to use for the channel.

    Returns Promise<Channel>

  • Creates a custom command.

    Attempts to create a command using the provided command object. If the command is successfully created, the method returns true. If an error occurs during the creation of the command, the method logs the error and returns false.

    Parameters

    • command: Command

      The command to be created.

    Returns Promise<boolean>

    A promise that resolves to true if the command was successfully created, or false otherwise.

  • Creates a token for the given user ID using the chat provider.

    Parameters

    • userId: string

      The ID of the user for whom the token is being created.

    Returns string

    A token for the provided user ID.

  • Removes a custom command from the getstream app. Before deleting the command, it first removes the command from any active channel types that are using it.

    Parameters

    • name: string

      The identifier of the command to be deleted.

    Returns Promise<void>

    await deleteCommand('ban');
    
  • Retrieves a chat channel based on its type and ID.

    Parameters

    • channelId: string

      The ID of the chat channel to retrieve.

    • channelTypeName: TRIP

      The type of the chat channel to retrieve.

    Returns Promise<null | Channel>

    the matched chat channel or null if not found.

  • Removes users to a channel using the chat provider.

    Parameters

    • channelId: string

      The ID of the channel to which the user will be added.

    • channelTypeName: TRIP

      The type of the channel to which the user will be added.

    • userIds: string[]

      The IDs of the users to remove from the channel.

    Returns Promise<Channel>

  • Sends a message to a chat channel.

    Parameters

    • channelId: string

      The ID of the channel to which the message will be sent.

    • channelTypeName: TRIP

      The type of the channel to which the message will be sent.

    • senderId: string

      The user who is sending the message

    • message: ChatMessage

      The message to send.

    Returns Promise<boolean>

    A promise that resolves with a boolean that designates if the message sent.

  • Updates a custom command.

    Attempts to update a command with the specified name using the provided options object. If the command is successfully updated, the method returns true. If an error occurs during the update of the command, the method logs the error and returns false.

    Parameters

    • name: string

      The name of the command to be updated.

    • options: CommandUpdate

      The options object containing the new values for the command.

    Returns Promise<boolean>

    A promise that resolves to true if the command was successfully updated, or false otherwise.