Add a sample app that sends a Twilio SMS anytime Mongo is updated
This was an interesting example I found in the Mulesoft GitHub repos. It seemed like a perfect candidate for Riff/Mu/Lambda, so I sketched out what it might look like.
This commit is contained in:
parent
bbe6280d46
commit
1ae888ce02
14
examples/mongo_twilio/README.md
Normal file
14
examples/mongo_twilio/README.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
# mongo_twilio
|
||||
|
||||
This sample sends an SMS via Twilio to any new customer entry added to a MongoDB database.
|
||||
|
||||
This is derived from Mulesoft's sample app here:
|
||||
https://github.com/mulesoft/twilio-connector/tree/master/example-send-sms-interact-with-mongo
|
||||
|
||||
Assuming we are deploying to AWS, running `$ mu deploy app.js` creates a new CloudFormation stack. That stack includes
|
||||
a single lambda that is triggered off modifications to the `clients` MongoDB database. This database is not provisioned
|
||||
by this stack; instead, we use name-based discovery to find an existing database configured in the environment.
|
||||
|
||||
In fact, many configuration entries are automatically plumbed around in this example, which are passed manually in the
|
||||
Mulesoft example. For instance, the Twilio account SID and "from" phone number, are configured per stack deployment.
|
||||
|
15
examples/mongo_twilio/app.js
Normal file
15
examples/mongo_twilio/app.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
// This code is the moral equivalent of Mulesoft's example "code" here:
|
||||
// https://github.com/mulesoft/twilio-connector/blob/master/example-send-sms-interact-with-mongo/src/main/app/mule-config.xml
|
||||
|
||||
var mu = require("mu");
|
||||
var mongo = require("mu-mongo");
|
||||
var twilio = require("mu-twilio");
|
||||
|
||||
var clients = mongo.connect("clients");
|
||||
clients.forEach(client =>
|
||||
twilio.sendSmsMessage({
|
||||
to: cust.phone,
|
||||
body: `Hi ${client.name}! Your account balance is USD${client.accountBalance}`,
|
||||
});
|
||||
);
|
||||
|
Loading…
Reference in a new issue