Plivo
透過集合功能整理內容 你可以依據偏好儲存及分類內容。
傳送簡訊
/** * An example of sending SMS messages from Google Ads Scripts using Plivo. * See: https://developers.google.com/google-ads/scripts/docs/features/third-party-apis#basic_authentication_samples * for full details on configuration. */ // Supply an email address: If for some reason your Plivo account // details become invalid or change, this will be used to make sure // you are notified of failure. const EMAIL_ADDRESS = 'INSERT_EMAIL_ADDRESS'; // The number you wish messages to appear to originate from. Must be registered // with Plivo. const PLIVO_SRC_PHONE_NUMBER = 'INSERT_SRC_PHONE_NUMBER'; // Account details, see: https://manage.plivo.com/dashboard/ const PLIVO_ACCOUNT_AUTHID = 'INSERT_ACCOUNT_AUTHID'; const PLIVO_ACCOUNT_AUTHTOKEN = 'INSERT_ACCOUNT_AUTHTOKEN'; /** * Builds an SMS message for sending with Plivo and sends the message. * @param {string} dstPhoneNumber The destination number. This is a string as * telephone numbers may contain '+'s or be prefixed with '00' etc. * @param {string} message The text message to send. */ function sendPlivoSms(dstPhoneNumber, message) { const request = buildPlivoMessageRequest(dstPhoneNumber, message); sendSms(request); } /** * Send an SMS message * @param {!SmsRequest} request The request object to send */ function sendSms(request) { const retriableErrors = [429, 500, 503]; for (let attempts = 0; attempts < 3; attempts++) { const response = UrlFetchApp.fetch(request.url, request.options); const responseCode = response.getResponseCode(); if (responseCode < 400 || retriableErrors.indexOf(responseCode) === -1) { break; } Utilities.sleep(2000 * Math.pow(2, attempts)); } if (responseCode >= 400 && EMAIL_ADDRESS) { MailApp.sendEmail( EMAIL_ADDRESS, 'Error sending SMS Message from Google Ads Scripts', response.getContentText()); } } /** * Builds a SMS request object specific for the Plivo service. * @param {string} recipientPhoneNumber Destination number including country * code. * @param {string} textMessage The message to send. * @return {SmsRequest} */ function buildPlivoMessageRequest(recipientPhoneNumber, textMessage) { if (!recipientPhoneNumber) { throw Error('No "recipientPhoneNumber" specified in call to ' + 'buildPlivoMessageRequest. "recipientPhoneNumber" cannot be empty'); } if (!textMessage) { throw Error('No "textMessage" specified in call to ' + 'buildPlivoMessageRequest. "textMessage" cannot be empty'); } const plivoUri = `https://api.plivo.com/v1/Account/${PLIVO_ACCOUNT_AUTHID}/Message/`; const authHeader = 'Basic ' + Utilities.base64Encode( PLIVO_ACCOUNT_AUTHID + ':' + PLIVO_ACCOUNT_AUTHTOKEN); const options = { muteHttpExceptions: true, method: 'POST', headers: {'Authorization': authHeader, 'Content-Type': 'application/json'}, payload: JSON.stringify({ src: PLIVO_SRC_PHONE_NUMBER, dst: recipientPhoneNumber, text: textMessage }) }; return {url: plivoUri, options: 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 enables sending SMS messages directly from Google Ads scripts using the Plivo service.\u003c/p\u003e\n"],["\u003cp\u003eIt requires setting up Plivo account details, including authentication credentials and a registered source phone number.\u003c/p\u003e\n"],["\u003cp\u003eThe script provides functionalities for building SMS message requests with recipient details and message content, sending the messages, and handling potential errors with retries and email notifications.\u003c/p\u003e\n"],["\u003cp\u003eUsers need to replace placeholders like \u003ccode\u003eINSERT_EMAIL_ADDRESS\u003c/code\u003e, \u003ccode\u003eINSERT_SRC_PHONE_NUMBER\u003c/code\u003e, \u003ccode\u003eINSERT_ACCOUNT_AUTHID\u003c/code\u003e, and \u003ccode\u003eINSERT_ACCOUNT_AUTHTOKEN\u003c/code\u003e with their actual values for the script to function correctly.\u003c/p\u003e\n"]]],[],null,["# Plivo\n\nSend a SMS message\n------------------\n\n```gdscript\n/**\n * An example of sending SMS messages from Google Ads Scripts using Plivo.\n * See: https://developers.google.com/google-ads/scripts/docs/features/third-party-apis#basic_authentication_samples\n * for full details on configuration.\n */\n\n// Supply an email address: If for some reason your Plivo account\n// details become invalid or change, this will be used to make sure\n// you are notified of failure.\nconst EMAIL_ADDRESS = 'INSERT_EMAIL_ADDRESS';\n\n// The number you wish messages to appear to originate from. Must be registered\n// with Plivo.\nconst PLIVO_SRC_PHONE_NUMBER = 'INSERT_SRC_PHONE_NUMBER';\n\n// Account details, see: https://manage.plivo.com/dashboard/\nconst PLIVO_ACCOUNT_AUTHID = 'INSERT_ACCOUNT_AUTHID';\nconst PLIVO_ACCOUNT_AUTHTOKEN = 'INSERT_ACCOUNT_AUTHTOKEN';\n\n/**\n * Builds an SMS message for sending with Plivo and sends the message.\n * @param {string} dstPhoneNumber The destination number. This is a string as\n * telephone numbers may contain '+'s or be prefixed with '00' etc.\n * @param {string} message The text message to send.\n */\nfunction sendPlivoSms(dstPhoneNumber, message) {\n const request =\n buildPlivoMessageRequest(dstPhoneNumber, message);\n sendSms(request);\n}\n\n/**\n * Send an SMS message\n * @param {!SmsRequest} request The request object to send\n */\nfunction sendSms(request) {\n const retriableErrors = [429, 500, 503];\n\n for (let attempts = 0; attempts \u003c 3; attempts++) {\n const response = UrlFetchApp.fetch(request.url, request.options);\n const responseCode = response.getResponseCode();\n\n if (responseCode \u003c 400 || retriableErrors.indexOf(responseCode) === -1) {\n break;\n }\n Utilities.sleep(2000 * Math.pow(2, attempts));\n }\n\n if (responseCode \u003e= 400 && EMAIL_ADDRESS) {\n MailApp.sendEmail(\n EMAIL_ADDRESS, 'Error sending SMS Message from Google Ads Scripts',\n response.getContentText());\n }\n}\n\n/**\n * Builds a SMS request object specific for the Plivo service.\n * @param {string} recipientPhoneNumber Destination number including country\n * code.\n * @param {string} textMessage The message to send.\n * @return {SmsRequest}\n */\nfunction buildPlivoMessageRequest(recipientPhoneNumber, textMessage) {\n if (!recipientPhoneNumber) {\n throw Error('No \"recipientPhoneNumber\" specified in call to ' +\n 'buildPlivoMessageRequest. \"recipientPhoneNumber\" cannot be empty');\n }\n if (!textMessage) {\n throw Error('No \"textMessage\" specified in call to ' +\n 'buildPlivoMessageRequest. \"textMessage\" cannot be empty');\n }\n const plivoUri =\n `https://api.plivo.com/v1/Account/${PLIVO_ACCOUNT_AUTHID}/Message/`;\n\n const authHeader = 'Basic ' +\n Utilities.base64Encode(\n PLIVO_ACCOUNT_AUTHID + ':' + PLIVO_ACCOUNT_AUTHTOKEN);\n const options = {\n muteHttpExceptions: true,\n method: 'POST',\n headers: {'Authorization': authHeader, 'Content-Type': 'application/json'},\n payload: JSON.stringify({\n src: PLIVO_SRC_PHONE_NUMBER,\n dst: recipientPhoneNumber,\n text: textMessage\n })\n };\n return {url: plivoUri, options: options};\n}\n```"]]