chat

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package chat is a lightweight wrapper over the "chat" methods in Slack's Web API: https://api.slack.com/methods?filter=chat.

Index

Constants

View Source
const (
	DefaultApprovalGreenButton = "Approve"
	DefaultApprovalRedButton   = "Deny"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Vars sdkservices.Vars
}

func (API) Delete

func (a API) Delete(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error)

Delete an existing message sent by the caller.

Based on: https://api.slack.com/methods/chat.delete

Required Slack app scopes:

func (API) PostEphemeral

func (a API) PostEphemeral(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error)

PostEphemeral sends an ephemeral message to a user in a group/channel (visible only to the assigned user). For text formatting tips, see https://api.slack.com/reference/surfaces/formatting. This message may also contain a rich layout and/or interactive blocks: https://api.slack.com/messaging/composing/layouts.

It returns the channel ID and the message's timestamp, but this timestamp may not be used for subsequent updates.

https://api.slack.com/methods/chat.postEphemeral#markdown: ephemeral message delivery is not guaranteed — the user must be currently active in Slack and a member of the specified channel. By nature, ephemeral messages do not persist across reloads, desktop and mobile apps, or sessions. Once the session is closed, ephemeral messages will disappear and cannot be recovered.

Based on: https://api.slack.com/methods/chat.postEphemeral

Required Slack app scopes:

func (API) PostMessage

func (a API) PostMessage(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error)

PostMessage sends a message to a user/group/channel. For text formatting tips, see https://api.slack.com/reference/surfaces/formatting. This message may also contain a rich layout and/or interactive blocks: https://api.slack.com/messaging/composing/layouts.

It returns the channel ID, the message's timestamp (for subsequent updates or in-thread replies), and a copy of the rendered message.

Based on: https://api.slack.com/methods/chat.postMessage

Required Slack app scopes:

func (API) SendApprovalMessage

func (a API) SendApprovalMessage(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error)

SendApprovalMessage sends an interactive message to a user/group/channel, with a short header, a longer message, and 2 buttons. For message formatting tips, see https://api.slack.com/reference/surfaces/formatting.

It returns the channel ID, the message's timestamp (for subsequent updates or in-thread replies), and a copy of the rendered message. The user's button choice will be relayed as an asynchronous interaction event.

This is a convenience wrapper over [PostMessage].

func (API) SendTextMessage

func (a API) SendTextMessage(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error)

SendTextMessage sends a message to a user/group/channel. For text formatting tips, see https://api.slack.com/reference/surfaces/formatting.

It returns the channel ID, the message's timestamp (for subsequent updates or in-thread replies), and a copy of the rendered message.

This is a convenience wrapper over [PostMessage].

func (API) Update

func (a API) Update(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error)

Update an existing message sent by the caller. For text formatting tips, see https://api.slack.com/reference/surfaces/formatting. This message may also contain a rich layout and/or interactive blocks: https://api.slack.com/messaging/composing/layouts.

It returns the channel ID, the message's timestamp (for subsequent updates or in-thread replies), and a copy of the rendered message.

Based on: https://api.slack.com/methods/chat.update

Required Slack app scopes:

type Block

type Block struct {
	// Valid values: "actions", "context", "divider", "header", or "section".
	// TODO: add the rest too - "file", "image", "input", and "video".
	Type string `json:"type,omitempty"`
	// https://api.slack.com/reference/block-kit/composition-objects#text.
	// Header: maximum length for the text in this field is 150 characters.
	// Section: maximum length for the text in this field is 3000 characters.
	Text *Text `json:"text,omitempty"`
	// https://api.slack.com/reference/block-kit/block-elements.
	// Actions: maximum of 25 elements. Context: maximum of 10 elements.
	// TODO: Support other element types.
	Elements []Button `json:"elements,omitempty"`
	// Maximum length is 255 characters. It should be unique for each message and
	// each iteration of a message. If a message is updated, use a new value.
	BlockID string `json:"block_id,omitempty"`
}

https://api.slack.com/reference/block-kit/blocks

type BotProfile

type BotProfile struct {
	ID     string `json:"id,omitempty"`
	AppID  string `json:"app_id,omitempty"`
	TeamID string `json:"team_id,omitempty"`

	Name string `json:"name,omitempty"`

	Deleted bool `json:"deleted,omitempty"`
	Updated int  `json:"updated,omitempty"`
}

type Button

type Button struct {
	// Type must be "button".
	Type string `json:"type,omitempty"`
	// Text's type must be "plain_text", may truncate with ~30 characters,
	// maximum length is 75 characters.
	Text *Text `json:"text,omitempty"`
	// ActionID can be used when receiving an interaction payload to identify the
	// action's source (https://api.slack.com/interactivity/handling#payloads).
	// Should be unique among all other [ActionId]s in the containing block.
	ActionID string `json:"action_id,omitempty"`
	// URL to load in the user's browser when the button is clicked. Maximum
	// length is 3000 characters. If you're using this, you'll
	// still receive an interaction payload and need to send an acknowledgement
	// response (https://api.slack.com/interactivity/handling#acknowledgment_response).
	URL string `json:"url,omitempty"`
	// Value to send along with the interaction payload.
	// Maximum length is 2000 characters.
	Value string `json:"value,omitempty"`
	// Style is optional. Decorates buttons with alternative visual color
	// schemes. Use this option with restraint. If specified, must be either
	// "primary" (green) or "danger" (red).
	Style string `json:"style,omitempty"`
	// AccessibilityLabel for longer descriptive text about the button. This
	// label will be read out by screen readers instead of the Text object.
	// Maximum length is 75 characters.
	AccessibilityLabel string `json:"accessibility_label,omitempty"`
}

https://api.slack.com/reference/block-kit/block-elements#button

type DeleteRequest

type DeleteRequest struct {
	// Channel containing the message to be deleted. Required.
	// https://api.slack.com/methods/chat.postMessage#channels
	Channel string `json:"channel"`
	// TS is a timestamp of the message to be deleted. Required.
	TS string `json:"ts"`
}

https://api.slack.com/methods/chat.delete#args

type DeleteResponse

type DeleteResponse struct {
	api.SlackResponse

	Channel string `json:"channel,omitempty"`
	TS      string `json:"ts,omitempty"`
}

https://api.slack.com/methods/chat.delete#examples

type Edited

type Edited struct {
	User string `json:"user,omitempty"`
	TS   string `json:"ts,omitempty"`
}

type Message

type Message struct {
	Type    string `json:"type,omitempty"`
	Subtype string `json:"subtype,omitempty"`
	// https://api.slack.com/events/message#hidden_subtypes
	Hidden bool `json:"hidden,omitempty"`

	Text   string  `json:"text,omitempty"`
	Blocks []Block `json:"blocks,omitempty"`
	Edited *Edited `json:"edited,omitempty"`

	User         string      `json:"user,omitempty"`
	AppID        string      `json:"app_id,omitempty"`
	BotID        string      `json:"bot_id,omitempty"`
	BotProfile   *BotProfile `json:"bot_profile,omitempty"`
	ParentUserID string      `json:"parent_user_id,omitempty"`

	Team        string `json:"team,omitempty"`
	Channel     string `json:"channel,omitempty"`
	ChannelType string `json:"channel_type,omitempty"`
	TS          string `json:"ts,omitempty"`
	EventTS     string `json:"event_ts,omitempty"`
	Permalink   string `json:"permalink,omitempty"`

	// https://api.slack.com/types/conversation
	// https://api.slack.com/methods/conversations.replies#examples
	ReplyCount      int      `json:"reply_count,omitempty"`
	ReplyUsersCount int      `json:"reply_users_count,omitempty"`
	LatestReply     string   `json:"latest_reply,omitempty"`
	ReplyUsers      []string `json:"reply_users,omitempty"`
	LastRead        string   `json:"last_read,omitempty"`
	UnreadCount     int      `json:"unread_count,omitempty"`
	// A count of messages that the calling user has yet to read that
	// matter to them (excludes things like join/leave messages).
	UnreadCountDisplay int  `json:"unread_count_display,omitempty"`
	IsLocked           bool `json:"is_locked,omitempty"`
	Subscribed         bool `json:"subscribed,omitempty"`

	// https://api.slack.com/events/message#stars
	IsStarred bool       `json:"is_starred,omitempty"`
	PinnedTo  []string   `json:"pinned_to,omitempty"`
	Reactions []Reaction `json:"reactions,omitempty"`

	// https://api.slack.com/events/message/channel_join
	Inviter string `json:"inviter,omitempty"`
	// https://api.slack.com/events/message/channel_name
	Name    string `json:"name,omitempty"`
	OldName string `json:"old_name,omitempty"`
	// https://api.slack.com/events/message/channel_purpose
	Purpose string `json:"purpose,omitempty"`
	// https://api.slack.com/events/message/channel_topic
	Topic string `json:"topic,omitempty"`

	// https://api.slack.com/events/message/message_changed
	Message         *Message `json:"message,omitempty"`
	PreviousMessage *Message `json:"previous_message,omitempty"`
	// https://api.slack.com/events/message/message_deleted
	DeletedTS string `json:"deleted_ts,omitempty"`
	// https://api.slack.com/events/message/message_replied
	ThreadTS string `json:"thread_ts,omitempty"`

	// https://api.slack.com/events/message/thread_broadcast
	Root *Message `json:"root,omitempty"`

	ClientMsgID string `json:"client_msg_id,omitempty"`
}

https://api.slack.com/types/conversation https://api.slack.com/methods/conversations.history#examples https://api.slack.com/methods/conversations.replies#examples https://github.com/slackapi/slack-api-specs/blob/master/web-api ("objs_message") https://api.slack.com/events/message

type PostEphemeralRequest

type PostEphemeralRequest struct {
	// https://api.slack.com/methods/chat.postEphemeral#target-channels-and-users
	Channel string `json:"channel"`
	// User ID of the user who will receive the ephemeral message. The user
	// should be in the channel specified by the channel argument. Required.
	User string `json:"user"`

	// https://api.slack.com/reference/surfaces/formatting
	// https://api.slack.com/methods/chat.postEphemeral#markdown
	Text string `json:"text,omitempty"`
	// https://api.slack.com/reference/block-kit
	// https://api.slack.com/messaging/composing/layouts
	// https://api.slack.com/messaging/interactivity
	// https://app.slack.com/block-kit-builder/
	Blocks []Block `json:"blocks,omitempty"`

	// ThreadTS provides another message's [TS] value to make this message
	// a reply. Avoid using a reply's [TS] value; use its parent instead.
	// See https://api.slack.com/methods/chat.postMessage#threads.
	ThreadTS string `json:"thread_ts,omitempty"`
}

https://api.slack.com/methods/chat.postEphemeral#args

type PostEphemeralResponse

type PostEphemeralResponse struct {
	api.SlackResponse

	Channel   string `json:"channel,omitempty"`
	MessageTS string `json:"message_ts,omitempty"`
}

https://api.slack.com/methods/chat.postEphemeral#examples

type PostMessageRequest

type PostMessageRequest struct {
	// See https://api.slack.com/methods/chat.postMessage#channels.
	// Slack user ID ("U"), user DM ID ("D"), multi-person/group DM ID ("G"),
	// channel ID ("C"), channel name (with or without the "#" prefix). Note
	// that all targets except "U", "D" and public channels require our Slack
	// app to be added in advance. Required.
	Channel string `json:"channel"`

	// https://api.slack.com/reference/surfaces/formatting
	// https://api.slack.com/methods/chat.postMessage#blocks_and_attachments
	Text string `json:"text,omitempty"`
	// https://api.slack.com/reference/block-kit
	// https://api.slack.com/messaging/composing/layouts
	// https://api.slack.com/messaging/interactivity
	// https://app.slack.com/block-kit-builder/
	Blocks []Block `json:"blocks,omitempty"`

	// ThreadTS provides another message's [TS] value to make this message
	// a reply. Avoid using a reply's [TS] value; use its parent instead.
	// See https://api.slack.com/methods/chat.postMessage#threads.
	ThreadTS string `json:"thread_ts,omitempty"`
	// ReplyBroadcast is used in conjunction with [ThreadTS] and indicates
	// whether the reply should be made visible to everyone in the channel
	// or conversation. Default = false.
	ReplyBroadcast bool `json:"reply_broadcast,omitempty"`
}

https://api.slack.com/methods/chat.postMessage#args

type PostMessageResponse

type PostMessageResponse struct {
	api.SlackResponse

	Channel string   `json:"channel,omitempty"`
	TS      string   `json:"ts,omitempty"`
	Message *Message `json:"message,omitempty"`
}

https://api.slack.com/methods/chat.postMessage#examples

type Reaction

type Reaction struct {
	Name  string   `json:"name,omitempty"`
	Users []string `json:"users,omitempty"`
	Count int      `json:"count,omitempty"`
}

https://api.slack.com/events/message

type SendApprovalMessageRequest

type SendApprovalMessageRequest struct {
	// Slack user ID ("U"), user DM ID ("D"), multi-person/group DM ID ("G"),
	// channel ID ("C"), channel name (with or without the "#" prefix). All
	// targets except "U", "D" and public channels require our Slack app to
	// be added in advance.
	Target string `json:"target"`

	// Header text: up to 150 characters, no markdown, but may include emoji.
	Header string `json:"header,omitempty"`
	// Message text: up to 3000 characters, may include markdown and emoji.
	// See https://api.slack.com/reference/surfaces/formatting.
	Message string `json:"message,omitempty"`
	// Green button text (e.g. "Yes", "Approve", "Proceed"). No markdown, may
	// include emoji. May truncate with ~30 characters, maximum length is 75
	// characters. Default = "Approve".
	GreenButton string `json:"green_button,omitempty"`
	// Red button text (e.g. "No", "Deny", "Reject", "Abort"). No markdown, may
	// include emoji. May truncate with ~30 characters, maximum length is 75
	// characters. Default = "Deny".
	RedButton string `json:"red_button,omitempty"`

	// ThreadTS provides another message's [TS] value to make this message
	// a reply. Avoid using a reply's [TS] value; use its parent instead.
	// See https://api.slack.com/methods/chat.postMessage#threads.
	ThreadTS string `json:"thread_ts,omitempty"`
	// ReplyBroadcast is used in conjunction with [ThreadTS] and indicates
	// whether the reply should be made visible to everyone in the channel
	// or conversation. Defaults to false.
	ReplyBroadcast bool `json:"reply_broadcast,omitempty"`
}

type Text

type Text struct {
	// Type must be "mrkdwn" or "plain_text".
	Type string `json:"type,omitempty"`
	// Text from a minimum of 1 to a maximum of 3000 characters.
	// See https://api.slack.com/reference/surfaces/formatting.
	Text string `json:"text,omitempty"`
	// This field is only usable when [Type] is "plain_text".
	Emoji bool `json:"emoji,omitempty"`
	// When set to false (as is default) URLs will be auto-converted into
	// links, conversation names will be link-ified, and certain mentions will
	// be automatically parsed. Using a value of true will skip any preprocessing
	// of this nature, although you can still include manual parsing strings.
	// This field is only usable when Type is "mrkdwn". See
	// https://api.slack.com/reference/surfaces/formatting.
	Verbatim bool `json:"verbatim,omitempty"`
}

https://api.slack.com/reference/block-kit/composition-objects#text

type UpdateRequest

type UpdateRequest struct {
	// See https://api.slack.com/methods/chat.postMessage#channels.
	// Slack user ID ("U"), user DM ID ("D"), multi-person/group DM ID ("G"),
	// channel ID ("C"), channel name (with or without the "#" prefix). Note
	// that all targets except "U", "D" and public channels require our Slack
	// app to be added in advance. Required
	Channel string `json:"channel"`
	// Timestamp of the message to be updated. Required.
	TS string `json:"ts"`

	// https://api.slack.com/reference/surfaces/formatting
	// https://api.slack.com/methods/chat.postMessage#blocks_and_attachments
	Text string `json:"text,omitempty"`
	// https://api.slack.com/reference/block-kit
	// https://api.slack.com/messaging/composing/layouts
	// https://api.slack.com/messaging/interactivity
	// https://app.slack.com/block-kit-builder/
	Blocks []Block `json:"blocks,omitempty"`

	// ReplyBroadcast is used in conjunction with [TS] and indicates whether
	// the reply should be made visible to everyone in the channel or
	// conversation. Defaults to false.
	ReplyBroadcast bool `json:"reply_broadcast,omitempty"`
}

https://api.slack.com/methods/chat.update#args

type UpdateResponse

type UpdateResponse struct {
	api.SlackResponse

	Channel string   `json:"channel,omitempty"`
	TS      string   `json:"ts,omitempty"`
	Text    string   `json:"text,omitempty"`
	Message *Message `json:"message,omitempty"`
}

https://api.slack.com/methods/chat.update#examples

Jump to

Keyboard shortcuts

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