Slack
Gửi tin nhắn cho người dùng hoặc nhóm
/**
* 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);
}
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2024-09-10 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2024-09-10 UTC."],[[["This script demonstrates how to send messages to Slack using Google Ads Scripts, integrating with incoming webhooks for seamless communication."],["It includes a practical example of generating a Google Ads report, saving it to a spreadsheet, and sending the report link to Slack."],["Users can customize the Slack message content, channel, and sender information to fit their specific needs."],["The script leverages the UrlFetchApp to make HTTP requests to the Slack API for sending messages."]]],[]]