chatkit

package module
v0.0.0-...-8cd3907 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 9 Imported by: 1

README

Chatkit Retirement Announcement

We are sorry to say that as of April 23 2020, we will be fully retiring our Chatkit product. We understand that this will be disappointing to customers who have come to rely on the service, and are very sorry for the disruption that this will cause for them. Our sales and customer support teams are available at this time to handle enquiries and will support existing Chatkit customers as far as they can with transition. All Chatkit billing has now ceased , and customers will pay no more up to or beyond their usage for the remainder of the service. You can read more about our decision to retire Chatkit here: https://blog.pusher.com/narrowing-our-product-focus. If you are interested in learning about how you can build chat with Pusher Channels, check out our tutorials.

chatkit-server-go godoc-badge Build Status

Golang server SDK for Pusher Chatkit.

This package provides an interface to interact with the Chatkit service. It allows interacting with the core Chatkit service and other subservices.

Please report any bugs or feature requests via a GitHub issue on this repo.

Installation

$ go get github.com/pusher/chatkit-server-go

Go versions

This library requires Go versions >=1.9.

Getting started

Before processing, ensure that you have created an account on the Chatkit Dashboard. You'll then have to create a Chatkit instance and acquire credentials for it (all of which is available in the dashboard.)

A new client may be instantiated as follows

import "github.com/pusher/chatkit-server-go"

client, err := chatkit.NewClient("<YOUR_INSTANCE_LOCATOR>", "<YOUR_KEY>")
if err != nil {
	return err
}

// use client to make calls to the service

Deprecated versions

Versions of the library below 1.0.0 are deprecated and support for them will soon be dropped.

It is highly recommended that you upgrade to the latest version if you're on an older version. To view a list of changes, please refer to the CHANGELOG.

Tests

To run the tests, a Chatkit instance is required along with its credentials. CHATKIT_INSTANCE_LOCATOR and CHATKIT_INSTANCE_KEY are required to be set as environment variables. Note that the tests run against an actual cluster and are to be treated as integration tests.

$ go test -v

Documentation

Refer to GoDoc.

License

This code is free to use under the terms of the MIT license. Please refer to LICENSE.md for more information.

Documentation

Overview

Package chatkit is the Golang server SDK for Pusher Chatkit. This package provides functionality to interact with various Chatkit services.

More information can be found in the Chatkit docs: https://docs.pusher.com/chatkit/overview/.

Please report any bugs or feature requests at: https://github.com/pusher/chatkit-server-go.

Index

Constants

View Source
const GrantTypeClientCredentials = auth.GrantTypeClientCredentials

Variables

View Source
var ExplicitlyResetPushNotificationTitleOverride = &core.ExplicitlyResetPushNotificationTitleOverride

Functions

This section is empty.

Types

type Attachment

type Attachment = core.Attachment

type AuthenticateOptions

type AuthenticateOptions = auth.Options

type AuthenticatePayload

type AuthenticatePayload = auth.Payload

type Client

type Client struct {
	// contains filtered or unexported fields
}

Public interface for the library. It allows interacting with different Chatkit services.

func NewClient

func NewClient(instanceLocator string, key string) (*Client, error)

NewClient returns an instantiated instance that fulfils the Client interface.

func (*Client) AddUsersToRoom

func (c *Client) AddUsersToRoom(ctx context.Context, roomID string, userIDs []string) error

AddUsersToRoom adds new users to an existing room.

func (*Client) AssignGlobalRoleToUser

func (c *Client) AssignGlobalRoleToUser(ctx context.Context, userID string, roleName string) error

AssignGlobalRoleToUser assigns a previously created globally scoped role to a user.

func (*Client) AssignRoomRoleToUser

func (c *Client) AssignRoomRoleToUser(
	ctx context.Context,
	userID string,
	roomID string,
	roleName string,
) error

AssignRoomRoleToUser assigns a previously created room scoped role to a user.

func (*Client) Authenticate

func (c *Client) Authenticate(payload auth.Payload, options auth.Options) (*auth.Response, error)

Authenticate returns a token response along with headers and status code to be used within the context of a token provider. Currently, the only supported GrantType is GrantTypeClientCredentials.

func (*Client) AuthorizerRequest

func (c *Client) AuthorizerRequest(
	ctx context.Context,
	options platformclient.RequestOptions,
) (*http.Response, error)

AuthorizerRequest allows performing requests to the authorizer service and returns a raw HTTP response.

func (*Client) CoreRequest

func (c *Client) CoreRequest(
	ctx context.Context,
	options platformclient.RequestOptions,
) (*http.Response, error)

CoreRequest allows making requests to the core chatkit service and returns a raw HTTP response.

func (*Client) CreateGlobalRole

func (c *Client) CreateGlobalRole(ctx context.Context, options CreateRoleOptions) error

CreateGlobalRole allows creating a globally scoped role.

func (*Client) CreateRoom

func (c *Client) CreateRoom(ctx context.Context, options CreateRoomOptions) (Room, error)

CreateRoom creates a new room.

func (*Client) CreateRoomRole

func (c *Client) CreateRoomRole(ctx context.Context, options CreateRoleOptions) error

CreateRoomRole allows creating a room scoped role.

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, options CreateUserOptions) error

CreateUser creates a new chatkit user.

func (*Client) CreateUsers

func (c *Client) CreateUsers(ctx context.Context, users []CreateUserOptions) error

CreateUsers creates a batch of users.

func (*Client) CursorsRequest

func (c *Client) CursorsRequest(
	ctx context.Context,
	options platformclient.RequestOptions,
) (*http.Response, error)

CursorsRequest allows performing a request to the cursors service that returns a raw HTTP response.

func (*Client) DeleteGlobalRole

func (c *Client) DeleteGlobalRole(ctx context.Context, roleName string) error

DeleteGlobalRole deletes a previously created globally scoped role.

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(ctx context.Context, options DeleteMessageOptions) error

DeleteMessage allows a previously sent message to be deleted.

func (*Client) DeleteRoom

func (c *Client) DeleteRoom(ctx context.Context, roomID string) error

DeleteRoom deletes an existing room.

func (*Client) DeleteRoomRole

func (c *Client) DeleteRoomRole(ctx context.Context, roleName string) error

DeleteRoomRole deletes a previously created room scoped role.

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, userID string) error

DeleteUser deletes a previously created user.

func (*Client) EditMessage

func (c *Client) EditMessage(ctx context.Context, roomID string, messageID uint, options EditMessageOptions) error

EditMessage identifies an existing message by both its room and message id in order to replace it's content and sender id with updated values.

func (*Client) EditMultipartMessage

func (c *Client) EditMultipartMessage(ctx context.Context, roomID string, messageID uint, options EditMultipartMessageOptions) error

EditMultipartMessage identifies an existing message by both its room and message id in order to replace it's content and sender id with updated values.

func (*Client) EditSimpleMessage

func (c *Client) EditSimpleMessage(ctx context.Context, roomID string, messageID uint, options EditSimpleMessageOptions) error

EditSimpleMessage identifies an existing message by both its room and message id in order to replace it's content and sender id with updated values.

func (*Client) FetchMultipartMessage

func (c *Client) FetchMultipartMessage(
	ctx context.Context,
	options FetchMultipartMessageOptions,
) (MultipartMessage, error)

FetchMultipartMessage retrieves a single message previously sent to a room based on the options provided.

func (*Client) FetchMultipartMessages

func (c *Client) FetchMultipartMessages(
	ctx context.Context,
	roomID string,
	options GetRoomMessagesOptions,
) ([]MultipartMessage, error)

FetchMultipartMessages retrieves messages previously sent to a room based on the options provided.

func (*Client) GenerateAccessToken

func (c *Client) GenerateAccessToken(options auth.Options) (auth.TokenWithExpiry, error)

GenerateAccessToken generates a JWT token based on the options provided.

func (*Client) GenerateSUToken

func (c *Client) GenerateSUToken(options auth.Options) (auth.TokenWithExpiry, error)

GenerateSuToken generates a JWT token with the `su` claim.

func (*Client) GetPermissionsForGlobalRole

func (c *Client) GetPermissionsForGlobalRole(
	ctx context.Context,
	roleName string,
) ([]string, error)

GetPermissionsForGlobalRole returns permissions associated with a previously created global role.

func (*Client) GetPermissionsForRoomRole

func (c *Client) GetPermissionsForRoomRole(
	ctx context.Context,
	roleName string,
) ([]string, error)

GetPermissionsForRoomRole returns permissions associated with a previously created room role.

func (*Client) GetReadCursor

func (c *Client) GetReadCursor(ctx context.Context, userID string, roomID string) (Cursor, error)

GetReadCursor returns a single cursor that was set by a user in a room.

func (*Client) GetReadCursorsForRoom

func (c *Client) GetReadCursorsForRoom(ctx context.Context, roomID string) ([]Cursor, error)

GetReadCursorsForRoom returns a list of cursors that have been set for a room. This returns cursors irrespective of the user that set them.

func (*Client) GetRoles

func (c *Client) GetRoles(ctx context.Context) ([]Role, error)

GetRoles retrieves all roles associated with an instance.

func (*Client) GetRoom

func (c *Client) GetRoom(ctx context.Context, roomID string) (Room, error)

GetRoom retrieves an existing room.

func (*Client) GetRoomMessages

func (c *Client) GetRoomMessages(
	ctx context.Context,
	roomID string,
	options GetRoomMessagesOptions,
) ([]Message, error)

GetRoomMessages retrieves messages previously sent to a room based on the options provided.

func (*Client) GetRooms

func (c *Client) GetRooms(ctx context.Context, options GetRoomsOptions) ([]core.RoomWithoutMembers, error)

GetRooms retrieves a list of rooms based on the options provided.

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, userID string) (User, error)

GetUser retrieves a previously created Chatkit user.

func (*Client) GetUserJoinableRooms

func (c *Client) GetUserJoinableRooms(ctx context.Context, userID string) ([]Room, error)

GetUserJoinableRooms retrieves a list of rooms the use can join (not an existing member of) Private rooms are not returned as part of the response.

func (*Client) GetUserReadCursors

func (c *Client) GetUserReadCursors(ctx context.Context, userID string) ([]Cursor, error)

GetUserReadCursors returns a list of cursors that have been set across different rooms for the user.

func (*Client) GetUserRoles

func (c *Client) GetUserRoles(ctx context.Context, userID string) ([]Role, error)

GetUserRoles returns roles assosciated with a user.

func (*Client) GetUserRooms

func (c *Client) GetUserRooms(ctx context.Context, userID string) ([]Room, error)

GetUserRooms retrieves a list of rooms the user is an existing member of.

func (*Client) GetUsers

func (c *Client) GetUsers(ctx context.Context, options *GetUsersOptions) ([]User, error)

GetUsers retrieves a list of users based on the options provided.

func (*Client) GetUsersByID

func (c *Client) GetUsersByID(ctx context.Context, userIDs []string) ([]User, error)

GetUsersByID retrieves a list of users for the given id's.

func (*Client) RemoveGlobalRoleForUser

func (c *Client) RemoveGlobalRoleForUser(ctx context.Context, userID string) error

RemoveGlobalRoleForUser removes a previously assigned globally scoped role from a user. Users can only have one globall scoped role associated at any point.

func (*Client) RemoveRoomRoleForUser

func (c *Client) RemoveRoomRoleForUser(ctx context.Context, userID string, roomID string) error

RemoveRoomRoleForUser removes a previously assigned room scoped role from a user. Users can have multiple room roles associated with them, but only one role per room.

func (*Client) RemoveUsersFromRoom

func (c *Client) RemoveUsersFromRoom(ctx context.Context, roomID string, userIDs []string) error

RemoveUsersFromRoom removes existing members from a room.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, options SendMessageOptions) (uint, error)

SendMessage publishes a new message to a room.

func (*Client) SendMultipartMessage

func (c *Client) SendMultipartMessage(
	ctx context.Context,
	options SendMultipartMessageOptions,
) (uint, error)

SendMultipartMessage publishes a new multipart message to a room.

func (*Client) SendSimpleMessage

func (c *Client) SendSimpleMessage(
	ctx context.Context,
	options SendSimpleMessageOptions,
) (uint, error)

SendSimpleMessage publishes a new simple multipart message to a room.

func (*Client) SetReadCursor

func (c *Client) SetReadCursor(ctx context.Context, userID string, roomID string, position uint) error

SetReadCursor sets the cursor position for a room for a user. The position points to the message ID of a message that was sent to that room.

func (*Client) UpdatePermissionsForGlobalRole

func (c *Client) UpdatePermissionsForGlobalRole(
	ctx context.Context,
	roleName string,
	options UpdateRolePermissionsOptions,
) error

UpdatePermissionsForGlobalRole allows adding or removing permissions from a previously created globally scoped role.

func (*Client) UpdatePermissionsForRoomRole

func (c *Client) UpdatePermissionsForRoomRole(
	ctx context.Context,
	roleName string,
	options UpdateRolePermissionsOptions,
) error

UpdatePermissionsForRoomROle allows adding or removing permissions from a previously created room scoped role.

func (*Client) UpdateRoom

func (c *Client) UpdateRoom(ctx context.Context, roomID string, options UpdateRoomOptions) error

UpdateRoom allows updating an existing room.

func (*Client) UpdateUser

func (c *Client) UpdateUser(ctx context.Context, userID string, options UpdateUserOptions) error

UpdateUser allows updating a previously created user.

type CreateRoleOptions

type CreateRoleOptions = authorizer.CreateRoleOptions

type CreateRoomOptions

type CreateRoomOptions = core.CreateRoomOptions

type CreateUserOptions

type CreateUserOptions = core.CreateUserOptions

type Cursor

type Cursor = cursors.Cursor

type DeleteMessageOptions

type DeleteMessageOptions = core.DeleteMessageOptions

type EditMessageOptions

type EditMessageOptions = core.EditMessageOptions

type EditMultipartMessageOptions

type EditMultipartMessageOptions = core.EditMultipartMessageOptions

type EditSimpleMessageOptions

type EditSimpleMessageOptions = core.EditSimpleMessageOptions

type ErrorResponse

type ErrorResponse = platformclient.ErrorResponse

type FetchMultipartMessageOptions

type FetchMultipartMessageOptions = core.FetchMultipartMessageOptions

type FetchMultipartMessagesOptions

type FetchMultipartMessagesOptions = core.FetchMultipartMessagesOptions

type GetRoomMessagesOptions

type GetRoomMessagesOptions = core.GetRoomMessagesOptions

type GetRoomsOptions

type GetRoomsOptions = core.GetRoomsOptions

type GetUsersOptions

type GetUsersOptions = core.GetUsersOptions

type Message

type Message = core.Message

type MultipartMessage

type MultipartMessage = core.MultipartMessage

type NewAttachmentPart

type NewAttachmentPart = core.NewAttachmentPart

type NewInlinePart

type NewInlinePart = core.NewInlinePart

type NewPart

type NewPart = core.NewPart

type NewURLPart

type NewURLPart = core.NewURLPart

type Part

type Part = core.Part

type RequestOptions

type RequestOptions = platformclient.RequestOptions

type Role

type Role = authorizer.Role

type Room

type Room = core.Room

type RoomWithoutMembers

type RoomWithoutMembers = core.RoomWithoutMembers

type SendMessageOptions

type SendMessageOptions = core.SendMessageOptions

type SendMultipartMessageOptions

type SendMultipartMessageOptions = core.SendMultipartMessageOptions

type SendSimpleMessageOptions

type SendSimpleMessageOptions = core.SendSimpleMessageOptions

type UpdateRolePermissionsOptions

type UpdateRolePermissionsOptions = authorizer.UpdateRolePermissionsOptions

type UpdateRoomOptions

type UpdateRoomOptions = core.UpdateRoomOptions

type UpdateUserOptions

type UpdateUserOptions = core.UpdateUserOptions

type User

type User = core.User

Directories

Path Synopsis
internal
authenticator
Package authenticator exposes an interface that performs authentication and authorization.
Package authenticator exposes an interface that performs authentication and authorization.
authorizer
Package core expoeses the Authorizer API that allows making requests to the Chatkit Authorizer service.
Package core expoeses the Authorizer API that allows making requests to the Chatkit Authorizer service.
common
Package common provides helpers that are shared across the other packages.
Package common provides helpers that are shared across the other packages.
core
Package core exposes an interface that allows making requests to the core Chatkit API to allow operations to be performed against Users, Rooms and Messages.
Package core exposes an interface that allows making requests to the core Chatkit API to allow operations to be performed against Users, Rooms and Messages.
cursors
Package cursors exposes an interface that allows making requests to the Chatkit cursors service.
Package cursors exposes an interface that allows making requests to the Chatkit cursors service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL