Skip to content

steps/slack ​

Low-level Slack operations for factory-owned steps. Workflow code calls their #jigs/steps wrappers; waiting for a thread reply is waitForSlackReply from #jigs/routines. callSlack reaches any other Web API method from a factory's own "use step" function.

See Slack.

Errors ​

SlackApiError ​

Slack answered a Web API call with ok: false. Check code to handle one answer, such as already_reacted.

Extends ​

Constructors ​

Constructor ​
ts
new SlackApiError(
   method, 
   code, 
   needed?, 
   answer?): SlackApiError;
Parameters ​
ParameterType
methodstring
codestring
needed?string
answer?{ body: string; status: number; }
answer.body?string
answer.status?number
Returns ​

SlackApiError

Overrides ​

ProviderApiError.constructor

Properties ​

PropertyTypeDescription
bodystring-
codestringSlack's error string, such as invalid_auth or already_reacted.
hint?stringWhat the reader can do about it. Quote each command to run in backticks, as in stop the service first: `pnpm exec jigs service stop` : the CLI prints it on its own line.
providerProvider-
statusnumber-

Create and update ​

postSlackMessage() ​

ts
function postSlackMessage(__namedParameters): Promise<string>;

Post plain mrkdwn text to a channel, or as a reply in the thread under threadTs, as the bot of the Slack installation installationName names. Returns the new message's ts.

Parameters ​

ParameterType
__namedParameters{ channel: string; installationName: string; text: string; threadTs?: string; }
__namedParameters.channelstring
__namedParameters.installationNamestring
__namedParameters.textstring
__namedParameters.threadTs?string

Returns ​

Promise<string>

Read ​

fetchSlackMessage() ​

ts
function fetchSlackMessage(__namedParameters): Promise<SlackMessageSnapshot>;

Read a Slack message, its permalink and its thread's replies, with each author's name and email, through the Slack installation installationName names.

Parameters ​

ParameterType
__namedParameters{ channel: string; installationName: string; ts: string; }
__namedParameters.channelstring
__namedParameters.installationNamestring
__namedParameters.tsstring

Returns ​

Promise<SlackMessageSnapshot>

Remarks ​

ts must be a top-level message. A reply's ts fails the step without a retry, naming the top-level message's ts.

Any Web API method ​

SlackParams ​

ts
type SlackParams = Record<string, JsonValue | undefined>;

Web API arguments. A value that is not a string is sent JSON-encoded, the way Slack takes blocks.


callSlack() ​

ts
function callSlack<T>(
   method, 
   params, 
options): Promise<T>;

Call any Slack Web API method as the factory's bot in the Slack installation installationName names, and return Slack's response body. Wrap it in your own "use step" function.

Type Parameters ​

Type ParameterDefault type
TRecord<string, unknown>

Parameters ​

ParameterType
methodstring
paramsSlackParams
options{ installationName: string; }
options.installationNamestring

Returns ​

Promise<T>

Remarks ​

Arguments that are not strings, such as blocks, are sent JSON-encoded, and undefined ones are left out. When Slack answers ok: false, it throws a SlackApiError with Slack's error as its code. Rate-limited calls are retried.

A step can run more than once, so a call that is not safe to repeat has to accept what a repeat gets back, such as already_reacted from reactions.add, or message_not_found once the message is deleted. Add any scope the method needs that jigs does not already use to the app's bot scopes in the hub; without it Slack answers missing_scope.

Example ​

ts
// workflows/deploys/steps.ts
import { callSlack, SlackApiError } from "@jigs-ai/jigs/steps/slack";

export async function react(channel: string, timestamp: string, name: string) {
  "use step";
  try {
    await callSlack(
      "reactions.add",
      { channel, timestamp, name },
      { installationName: "slack-acme" },
    );
  } catch (error) {
    const tolerated = ["already_reacted", "message_not_found"];
    if (!(error instanceof SlackApiError && tolerated.includes(error.code))) throw error;
  }
}