Integrations

Your app can post to Slack, message a Telegram group, text a customer through Twilio or call a webhook in another system. Connect the service once with its credentials, try a call, then call it from your workflows. Credentials are sealed, never shown again and never reach the browser or your code.

Built in

PieceDefault action and its propsCredentials (or project secrets)
slacksend_channel_message: channel, text, threadTsbot_token, channel (SLACK_BOT_TOKEN, SLACK_CHANNEL)
discordsend_message_webhook: content, usernamewebhook_url (DISCORD_WEBHOOK_URL)
telegram_botsend_text_message: chat_id, messagebot_token, chat_id
twiliosend_sms: from, to, bodyaccount_sid, auth_token, from
whatsappsendMessage: phone_number_id, to, textaccess_token, phone_number_id
googlechatsendAMessage: spaceId, textaccess_token or webhook_url
http, webhooksend_request (method, url, headers, body); send (url, body)none, or url (WEBHOOK_URL)

Also ntfy, Gotify and Mattermost. integrations { "action": "catalog" } lists everything this server can call, with each action's props and the credential fields a connection holds. A credential with a prop's name (a channel, a from number) is that prop's default. For a service that isn't there, call its API from an action with ctx.http.fetch and a secret by reference.

Step by step

integrations { "project_id": "…", "action": "connect", "piece": "slack",
               "credentials": { "bot_token": "xoxb-…", "channel": "C0123456789" } }    // env: dev, prod or all (default)

integrations { "project_id": "…", "action": "call", "piece": "slack",
               "input": { "text": "Hello from the app" } }                           // really sends, now

integrations { "project_id": "…" }      // the project's connections: field names, never values

Code

// workflows/signup.ts
import { on } from "@appbricx/workflows";

export const newMember = on.created<{ name: string; email: string | null }>("member_profile", async ({ row }, step) => {
  const posted = await step.run("post to Slack", async () => {
    try {
      await step.ctx.integrations.call("slack", { action: "send_channel_message", channel: "C0123456789",
                                                 text: "New sign-up: " + row.name });
      return true;
    } catch (e) {
      step.ctx.log("Slack: " + (e instanceof Error ? e.message : String(e)));   // not connected, or refused
      return false;
    }
  });
  return { posted };
});
  • ctx.integrations.call(piece, { action, …props }); action left out is the piece's default. ctx.integrations.invoke(piece, action, props) is the same with the action apart.
  • Inside step.run, so a retried run doesn't post twice.
  • It throws when the piece isn't connected ("integration not connected: slack"). Catch it when the rest of the run should go on.

Check it

workflows { "project_id": "…", "action": "dry_run", "id": "newmember", "row": { "name": "Test Person" } }
// the integration call is listed as an effect, nothing is posted
logs { "project_id": "…", "workflow": "newmember" }    // real runs, with what the service answered

Gotchas

  • Ids, not names. A Slack channel id like C0123456789, and invite the bot to private channels.
  • Production can have its own connection: connect with "env": "prod". Connecting for production (or all) needs the deploy scope.
  • A call from the tool really sends. On production it also asks for confirm_production.
  • Phone numbers need a country code for SMS and WhatsApp.

Related