Slack
Stay organized with collections
Save and categorize content based on your preferences.
Post a message to a user or group
/**
* An example of sending messages into Slack. See:
* https://developers.google.com/google-ads/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';
*/
const SLACK_URL = 'INSERT_WEBHOOK_URL_HERE';
// An example of retrieving an Google Ads Report and sending it in a slack message.
function sendReportToSlack() {
const report = AdsApp.report(
'SELECT CampaignName, Impressions, Clicks FROM ' +
'CAMPAIGN_PERFORMANCE_REPORT DURING YESTERDAY');
const spreadsheet = SpreadsheetApp.create('Report');
report.exportToSheet(spreadsheet.getActiveSheet());
// See https://api.slack.com/docs/message-formatting for message formatting.
const message = 'Your *Google Ads 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.
* '#google-ads' or a direct message e.g. '@sundar'. Defaults to '#general'.
*/
function sendSlackMessage(text, opt_channel) {
const slackMessage = {
text: text,
icon_url:
'https://www.gstatic.com/images/icons/material/product/1x/adwords_64dp.png',
username: 'Google Ads Scripts',
channel: opt_channel || '#general'
};
const options = {
method: 'POST',
contentType: 'application/json',
payload: JSON.stringify(slackMessage)
};
UrlFetchApp.fetch(SLACK_URL, options);
}
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-03-14 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-03-14 UTC."],[],[]]