0

I am using Plivo's SMS API to send SMS messages. Is it possible to have an user input prompt for “SENDERS NAME”, “RECEIVER NAME” and “MESSAGE” in Plivo’s SMS API without having them to be hardcoded before I run the .js file?

    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);
    }, );
})();
Sufian
  • 1

1 Answers1

0

Plivo's Developer Evangelist here. It depends upon your use case. Ideally not hardcoding values means storing values at some place like a Google Sheet, or having a front end to accept values from a user or a database. I suggest to the easiest way at this point is to prompt users right after running your js script.

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);
});

If you'd like to use a front end to prompt the user you can try this project. If you'd like to store values using a Google Sheet and trigger an SMS whenever a row is updated you can use an automation tool like Zapier.