Skip to main content
When you use prebuilt actions tied to apps, you don’t need to write the code to authorize API requests. Just connect your account for that app and run your workflow. But sometimes you’ll need to write your own code. You can also connect apps to custom code steps, using the auth information to authorize requests to that app. For example, you may want to send a Slack message from a step. We use Slack’s OAuth integration to authorize sending messages from your workflows. To wire up a Slack account to a workflow, define it as a prop to the workflow.
import { WebClient } from '@slack/web-api'
 
export default defineComponent({
  props: {
    // This creates a connection called "slack" that connects a Slack account.
    slack: {
      type: 'app',
      app: 'slack'
    }
  },
  async run({ steps, $ }) {
    const web = new WebClient(this.slack.$auth.oauth_access_token)
 
    return await web.chat.postMessage({
      text: "Hello, world!",
      channel: "#general",
    })
  }
});
Then click the Refresh fields button in the editor to render the Slack field based on the slack prop: