I’m trying to built a proof-of-concept to send a text message using observable. New to JS/observable and trying to figure out how to modify information on this page so that it will work in observable.
I’m trying to fiddle around, as a starting point I tried to do
twilio = require("firstname.lastname@example.org") but it says “unable to load module”.
If someone could please give some advice on what I’m doing wrong and how to go about getting started that would be greatly appreciated!
Ignoring the build issue for a second. Those are node.js instructions built under the idea you will keep that server private, hence it contains your twilio secret API key that must never be exposed in a public notebook.
So what is your plan for the secret storage, and probably authentication? Is the notebook public or private?
The idea is that the notebook would be private. Even if I made it a public unlisted notebook and shared the link with others I could still use a secret to hide the API key right?
No, Observable won’t let you publish a notebook that accesses Secrets.
You would have to set up a proxy server that delegates authenticated calls from your notebook to the Twilio API (and perhaps imposes additional restrictions). Even if you manage to load the node.js SDK in the browser, there’s still a good chance that the API endpoints aren’t CORS enabled.
no public unlisted notebooks don’t support the inbuilt observable secrets Introduction to Secrets / Observable / Observable
If you trust your uses not to abuse it and you keep it secret you can do something like Using Secrets for API keys in public notebooks (Airtable Example) / Endpoint Services / Observable
But for true public you need them to login so you can rate limit and ban them if they abuse the feature. Firebase auth works Firebase and Firebase UI / Tom Larkworthy / Observable
Got it. In my case I can trust the users. It wouldn’t matter if they saw the API key.
So the SDK you are targeting is a node.js one. Often, Web doesn’t work with nodejs libraries. Significant difference exist in libraries for handling memory (Buffer vs. TypedArray) and networking.
If the SDK doesn’t work, you can go through the REST API Twilio SMS API Overview - Twilio
I added email capabilities to my notebooks using Zapier, which does support Twilio too Zapier Cell Trigger / Endpoint Services / Observable