Skip to content

Instantly share code, notes, and snippets.

Created Jul 9, 2018
What would you like to do?
Using Dialog Box of Slack by Google Apps Script

Using Dialog Box of Slack by Google Apps Script

This is a GAS sample script for using a dialog box of Slack.

function doPost(e) {
  var params = e.parameter;
  var token = params.token;
  var text = params.text;
  var trigger_id = params.trigger_id;
  var slackUrl = "";
  if (token == "[token from slack]"){ // Please input this.
    var dialog = {
      "token": "[OAuth Token]", // Please input this.
      "trigger_id": trigger_id,
      "dialog": JSON.stringify({
        "callback_id": "ryde-46e2b0",
        "title": "Request a Ride",
        "submit_label": "Request",
        "elements": [
            "type": "text",
            "label": "Pickup Location",
            "name": "loc_origin"
            "type": "text",
            "label": "Dropoff Location",
            "name": "loc_destination"
    var options = {
      'method' : 'post',
      'payload' : dialog,
    UrlFetchApp.fetch(slackUrl, options);
    var res = {"text":"failed token verification!"} 
    return ContentService.createTextOutput(JSON.stringify(res)).setMimeType(ContentService.MimeType.JSON);
  return ContentService.createTextOutput(); // Important

Note :

When there are no exceptions within the dialog submission, your app must respond with 200 OK with an empty body. This will complete the dialog.

  • When it uses dialog, it returns the empty body using ContentService.createTextOutput() for above, because the status code cannot be customized by Google Apps Script. When the empty body is not returned, the error occurs.
  • This script supposes that your setting for using Slack dialog has already been done.
  • If you modified your script, please redeploy Web Apps as a new version. By this, the script of the latest version is reflected to Web Apps.

Reference :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment