Slack

Post a message to a user or group

/**
 * An example of sending messages into Slack. See:
 * https://developers.google.com/adwords/scripts/docs/features/third-party-apis
 *
 * Webhook set up at: https://api.slack.com/custom-integrations >
 * 'Set up an incoming webhook', follow the steps then click 'Add Incoming
 * WebHooks Integration'. This will create the URL needed for below, e.g:
 * 'https://hooks.slack.com/services/TXXXXXXX/BXXXXXXX/AAAAAAAAABBBBBBBBBBCCCC';
 */
var SLACK_URL = 'INSERT_WEBHOOK_URL_HERE';

// An example of retrieving an AdWords Report and sending it in a slack message.
function sendReportToSlack() {
  var report = AdWordsApp.report(
      'SELECT CampaignName, Impressions, Clicks FROM ' +
      'CAMPAIGN_PERFORMANCE_REPORT DURING YESTERDAY');
  var spreadsheet = SpreadsheetApp.create('Report');
  report.exportToSheet(spreadsheet.getActiveSheet());

  // See https://api.slack.com/docs/message-formatting for message formatting.
  var message = 'Your *AdWords Report* is ready! <' + spreadsheet.getUrl() +
      '|Click here>';
  sendSlackMessage(message);
}

/**
 * Sends a message to Slack
 * @param {string} text The message to send in slack formatting. See:
 *     https://api.slack.com/docs/message-formatting.
 * @param {string=} opt_channel An optional channel, which can be channel e.g.
 *     '#adwords' or a direct message e.g. '@sundar'. Defaults to '#general'.
 */
function sendSlackMessage(text, opt_channel) {
  var slackMessage = {
    text: text,
    icon_url:
        'https://www.gstatic.com/images/icons/material/product/1x/adwords_64dp.png',
    username: 'AdWords Scripts',
    channel: opt_channel || '#general'
  };

  var options = {
    method: 'POST',
    contentType: 'application/json',
    payload: JSON.stringify(slackMessage)
  };
  UrlFetchApp.fetch(SLACK_URL, options);
}

Send feedback about...

AdWords Scripts
AdWords Scripts
Need help? Visit our support page.