Resources »

Packages »

Slack Bot

Introduction

This package creates Slack Bot for demonstrating integration between Cerb and Slack’s API.

Configure the Slack service

If you haven’t already, follow these instructions to configure the Slack service and add your first connected account.

Import the package

Navigate to Setup » Configure » Import Package.

Paste the following package into the large text box:



{
  "package": {
    "name": "Slack Bot",
    "cerb_version": "9.1.0",
    "revision": 1,
    "requires": {
      "cerb_version": "9.1.0"
    },
    "configure": {
      "prompts": [
        {
          "type": "chooser",
          "label": "Slack Account:",
          "key": "slack_account_id",
          "params": {
            "context": "cerberusweb.contexts.connected_account",
            "single": true,
            "query": "name:slack"
          }
        }
      ],
      "placeholders": [

      ]
    }
  },
  "bots": [
    {
      "uid": "bot_36",
      "name": "Slack Bot",
      "owner": {
        "context": "cerberusweb.contexts.app",
        "id": 0
      },
      "is_disabled": false,
      "params": {
        "config": null,
        "events": {
          "mode": "all",
          "items": [

          ]
        },
        "actions": {
          "mode": "allow",
          "items": [
            "core.va.action.http_request"
          ]
        }
      },
      "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAADAFBMVEX///9jwaDgGlmJ09/ssy0li3QzFDPWICeBnDz9/v7//v6M1ODhH131+/v++/OS1+KP1uGH0dxow6M7nIvzznaBnkHstC/5/fz+9fjc8vXi9O7d8uv99+qc2+TH6d3668b447JgvqBSr5wqj3rkN27uukDttjXttTHssC3XISzu+fv+/Pjy+vjm9vj98vbt+PXX8PTI6/D75u2x4uqq4Oim3uej3eb99eTR7eOW2OP5z9z4ydi85df77c6r3sz0rcP56L+L0bh8y7B4yq10yKvte6BMp5700X/lPnPiJGDxxV+PqlzeG0+Dok7dHEhUH0DbHTzdOTQ2FDTXICr6/v7//P33/P3y+/zf8/bM7PHm9fC65ey25Oz74emf3OXL6+D8893A5tn88deJ0Nav4M+m3Mn1tMhyw8eT1L3xmraFz7Vvxajvh6j336fugaRlwqFeu6H23aD225ztd5xOrJrraZLpXYo2l4bnT4AukX7nR3ryy26wslngGlbwwlXtuD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iI4kMgxno9ZXHCnPUIN8QmCWrcuoeBfNklBfLFQ1mskaLWbdWdHh4eHj8cz8Bjv4sGY4wwrEAAAAASUVORK5CYII=",
      "behaviors": [
        {
          "uid": "behavior_189",
          "title": "API: api.test",
          "is_disabled": false,
          "is_private": true,
          "priority": 50,
          "event": {
            "key": "event.macro.bot",
            "label": "Custom behavior on bot"
          },
          "nodes": [
            {
              "type": "action",
              "title": "Execute HTTP request to Slack API",
              "status": "live",
              "params": {
                "actions": [
                  {
                    "action": "core.va.action.http_request",
                    "http_verb": "get",
                    "http_url": "{# See: https://api.slack.com/methods/api.test #}\r\nhttps://slack.com/api/api.test?example1=value1",
                    "http_headers": "",
                    "http_body": "",
                    "auth": "connected_account",
                    "auth_connected_account_id": "{{{slack_account_id}}}",
                    "options": {
                      "raw_response_body": "1"
                    },
                    "run_in_simulator": "1",
                    "response_placeholder": "_http_response"
                  },
                  {
                    "action": "_set_custom_var",
                    "value": "{{_http_response.body|json_pretty}}",
                    "format": "json",
                    "is_simulator_only": "0",
                    "var": "response_json"
                  }
                ]
              }
            }
          ]
        },
        {
          "uid": "behavior_190",
          "title": "API: bots.info",
          "is_disabled": false,
          "is_private": true,
          "priority": 50,
          "event": {
            "key": "event.macro.bot",
            "label": "Custom behavior on bot"
          },
          "variables": {
            "var_bot_id": {
              "key": "var_bot_id",
              "label": "Bot ID",
              "type": "S",
              "is_private": "0",
              "params": {
                "widget": "single"
              }
            }
          },
          "nodes": [
            {
              "type": "action",
              "title": "Execute HTTP request to Slack API",
              "status": "live",
              "params": {
                "actions": [
                  {
                    "action": "core.va.action.http_request",
                    "http_verb": "get",
                    "http_url": "{# See: https://api.slack.com/methods/bots.info #}\r\nhttps://slack.com/api/bots.info?bot={{var_bot_id|url_encode}}",
                    "http_headers": "",
                    "http_body": "",
                    "auth": "connected_account",
                    "auth_connected_account_id": "{{{slack_account_id}}}",
                    "options": {
                      "raw_response_body": "1"
                    },
                    "run_in_simulator": "1",
                    "response_placeholder": "_http_response"
                  },
                  {
                    "action": "_set_custom_var",
                    "value": "{{_http_response.body|json_pretty}}",
                    "format": "json",
                    "is_simulator_only": "0",
                    "var": "response_json"
                  }
                ]
              }
            }
          ]
        },
        {
          "uid": "behavior_193",
          "title": "API: channels.list",
          "is_disabled": false,
          "is_private": true,
          "priority": 50,
          "event": {
            "key": "event.macro.bot",
            "label": "Custom behavior on bot"
          },
          "nodes": [
            {
              "type": "action",
              "title": "Execute HTTP request to Slack API",
              "status": "live",
              "params": {
                "actions": [
                  {
                    "action": "core.va.action.http_request",
                    "http_verb": "get",
                    "http_url": "{# See: https://api.slack.com/methods/channels.list #}\r\nhttps://slack.com/api/channels.list",
                    "http_headers": "",
                    "http_body": "",
                    "auth": "connected_account",
                    "auth_connected_account_id": "{{{slack_account_id}}}",
                    "options": {
                      "raw_response_body": "1"
                    },
                    "run_in_simulator": "1",
                    "response_placeholder": "_http_response"
                  },
                  {
                    "action": "_set_custom_var",
                    "value": "{{_http_response.body|json_pretty}}",
                    "format": "json",
                    "is_simulator_only": "0",
                    "var": "response_json"
                  }
                ]
              }
            }
          ]
        },
        {
          "uid": "behavior_192",
          "title": "API: chat.postMessage",
          "is_disabled": false,
          "is_private": true,
          "priority": 50,
          "event": {
            "key": "event.macro.bot",
            "label": "Custom behavior on bot"
          },
          "variables": {
            "var_channel": {
              "key": "var_channel",
              "label": "Channel",
              "type": "S",
              "is_private": "0",
              "params": {
                "widget": "single"
              }
            },
            "var_message": {
              "key": "var_message",
              "label": "Message",
              "type": "S",
              "is_private": "0",
              "params": {
                "widget": "single"
              }
            }
          },
          "nodes": [
            {
              "type": "action",
              "title": "Execute HTTP request to Slack API",
              "status": "live",
              "params": {
                "actions": [
                  {
                    "action": "core.va.action.http_request",
                    "http_verb": "post",
                    "http_url": "{# See: https://api.slack.com/methods/chat.postMessage #}\r\nhttps://slack.com/api/chat.postMessage",
                    "http_headers": "Content-Type: application/x-www-form-urlencoded",
                    "http_body": "{% set params = {\r\n\t\"channel\": var_channel,\r\n\t\"text\": var_message,\r\n\t\"as_user\": \"false\",\r\n\t\"username\": \"Cerb\",\r\n} %}\r\n{{params|url_encode}}",
                    "auth": "connected_account",
                    "auth_connected_account_id": "{{{slack_account_id}}}",
                    "options": {
                      "raw_response_body": "1"
                    },
                    "run_in_simulator": "1",
                    "response_placeholder": "_http_response"
                  },
                  {
                    "action": "_set_custom_var",
                    "value": "{{_http_response.body|json_pretty}}",
                    "format": "json",
                    "is_simulator_only": "0",
                    "var": "response_json"
                  }
                ]
              }
            }
          ]
        },
        {
          "uid": "behavior_194",
          "title": "API: users.list",
          "is_disabled": false,
          "is_private": true,
          "priority": 50,
          "event": {
            "key": "event.macro.bot",
            "label": "Custom behavior on bot"
          },
          "nodes": [
            {
              "type": "action",
              "title": "Execute HTTP request to Slack API",
              "status": "live",
              "params": {
                "actions": [
                  {
                    "action": "core.va.action.http_request",
                    "http_verb": "get",
                    "http_url": "{# See: https://api.slack.com/methods/users.list #}\r\nhttps://slack.com/api/users.list",
                    "http_headers": "",
                    "http_body": "",
                    "auth": "connected_account",
                    "auth_connected_account_id": "{{{slack_account_id}}}",
                    "options": {
                      "raw_response_body": "1"
                    },
                    "run_in_simulator": "1",
                    "response_placeholder": "_http_response"
                  },
                  {
                    "action": "_set_custom_var",
                    "value": "{{_http_response.body|json_pretty}}",
                    "format": "json",
                    "is_simulator_only": "0",
                    "var": "response_json"
                  }
                ]
              }
            }
          ]
        },
        {
          "uid": "behavior_191",
          "title": "API: users.profile.get",
          "is_disabled": false,
          "is_private": true,
          "priority": 50,
          "event": {
            "key": "event.macro.bot",
            "label": "Custom behavior on bot"
          },
          "nodes": [
            {
              "type": "action",
              "title": "Execute HTTP request to Slack API",
              "status": "live",
              "params": {
                "actions": [
                  {
                    "action": "core.va.action.http_request",
                    "http_verb": "get",
                    "http_url": "{# See: https://api.slack.com/methods/users.profile.get #}\r\nhttps://slack.com/api/users.profile.get",
                    "http_headers": "",
                    "http_body": "",
                    "auth": "connected_account",
                    "auth_connected_account_id": "{{{slack_account_id}}}",
                    "options": {
                      "raw_response_body": "1"
                    },
                    "run_in_simulator": "1",
                    "response_placeholder": "_http_response"
                  },
                  {
                    "action": "_set_custom_var",
                    "value": "{{_http_response.body|json_pretty}}",
                    "format": "json",
                    "is_simulator_only": "0",
                    "var": "response_json"
                  }
                ]
              }
            }
          ]
        }
      ]
    }
  ]
}


Click the Import button.

You’ll be prompted to link the Slack connected account you created earlier.

Click the Import button again.

You should see the following:

Test the integration behaviors

Click on Slack Bot and then click Behaviors on its card.

Open the card for the API: chat.postMessage behavior.

Click on the Simulator button at the top of the card.

Click the Simulate button.

You should see a JSON response about the sent message.

You can use the simulator on the other behaviors to test them as well.

This message should pop up in your Slack channel:

Next steps

At this point you can modify the behaviors to meet your needs. You can use the responses from Slack’s API in your behaviors.