Slack
透過集合功能整理內容 你可以依據偏好儲存及分類內容。
向使用者或群組發布訊息
/** * 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); }
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eThis script demonstrates how to send messages to Slack using Google Ads Scripts, integrating with incoming webhooks for seamless communication.\u003c/p\u003e\n"],["\u003cp\u003eIt includes a practical example of generating a Google Ads report, saving it to a spreadsheet, and sending the report link to Slack.\u003c/p\u003e\n"],["\u003cp\u003eUsers can customize the Slack message content, channel, and sender information to fit their specific needs.\u003c/p\u003e\n"],["\u003cp\u003eThe script leverages the UrlFetchApp to make HTTP requests to the Slack API for sending messages.\u003c/p\u003e\n"]]],[],null,["# Slack\n\nPost a message to a user or group\n---------------------------------\n\n```gdscript\n/**\n * An example of sending messages into Slack. See:\n * https://developers.google.com/google-ads/scripts/docs/features/third-party-apis\n *\n * Webhook set up at: https://api.slack.com/custom-integrations \u003e\n * 'Set up an incoming webhook', follow the steps then click 'Add Incoming\n * WebHooks Integration'. This will create the URL needed for below, e.g:\n * 'https://hooks.slack.com/services/TXXXXXXX/BXXXXXXX/AAAAAAAAABBBBBBBBBBCCCC';\n */\nconst SLACK_URL = 'INSERT_WEBHOOK_URL_HERE';\n\n// An example of retrieving an Google Ads Report and sending it in a slack message.\nfunction sendReportToSlack() {\n const report = AdsApp.report(\n 'SELECT CampaignName, Impressions, Clicks FROM ' +\n 'CAMPAIGN_PERFORMANCE_REPORT DURING YESTERDAY');\n const spreadsheet = SpreadsheetApp.create('Report');\n report.exportToSheet(spreadsheet.getActiveSheet());\n\n // See https://api.slack.com/docs/message-formatting for message formatting.\n const message = 'Your *Google Ads Report* is ready! \u003c' + spreadsheet.getUrl() +\n '|Click here\u003e';\n sendSlackMessage(message);\n}\n\n/**\n * Sends a message to Slack\n * @param {string} text The message to send in slack formatting. See:\n * https://api.slack.com/docs/message-formatting.\n * @param {string=} opt_channel An optional channel, which can be channel e.g.\n * '#google-ads' or a direct message e.g. '@sundar'. Defaults to '#general'.\n */\nfunction sendSlackMessage(text, opt_channel) {\n const slackMessage = {\n text: text,\n icon_url:\n 'https://www.gstatic.com/images/icons/material/product/1x/adwords_64dp.png',\n username: 'Google Ads Scripts',\n channel: opt_channel || '#general'\n };\n\n const options = {\n method: 'POST',\n contentType: 'application/json',\n payload: JSON.stringify(slackMessage)\n };\n UrlFetchApp.fetch(SLACK_URL, options);\n}\n```"]]