我正在使用 Plivo 的 SMS API 发送 SMS 消息。是否可以在 Plivo 的 SMS API 中为“SENDERS NAME”、“RECEIVER NAME”和“MESSAGE”提供用户输入提示,而无需在我运行 .js 文件之前对其进行硬编码?
var plivo = require('plivo');
(function main() {
'use strict';
var client = new plivo.Client("<MY API KEY>", "<MY API TOKEN>");
client.messages.create(
"+1<SENDER NUMBER>", // Sender's phone number with country code
"+1<RECEIVER NUMBER>", // Receiver's phone Number with country code
"<MESSAGE>", // Message
{
method: "GET", // Method used to trigger message URL.
url: "http://example.com/sms_status/" // The URL to which with the status of the message is sent
},
).then(function(response) {
console.log(response);
}, );
})();
回答1
Plivo 的开发人员布道师在这里。这取决于您的用例。理想情况下,不硬编码 values 意味着将 values 存储在 Google Sheet 之类的某个地方,或者有一个前端来接受来自用户或数据库的 values。我建议此时最简单的方法是在运行您的 js 脚本后立即提示用户。
const prompt = require('prompt-sync')();
var plivo = require('plivo');
const from = prompt('Please enter source number?');
const to = prompt('Please enter destination number?');
const text = prompt('Please enter the text you would like to send?');
console.log(`User input details are, From: ${from}, To:${to}, Text: ${text}`);
var client = new plivo.Client("auth_id", "auth_token");
client.messages.create({
src: from,
dst: to,
text: text,
}).then(function(response) {
console.log(response);
});
如果你想使用前端来提示用户,你可以试试这个https://github.com/huzaif96/send-sms-dashboard。如果您想store values 使用 Google 表格并在更新行时触发 SMS,您可以使用自动化工具,例如 https://zapier.com/apps/plivo/integration。