r/elixir • • 11d ago

I published a Twilio SDK for Elixir, generated from Twilio's OpenAPI spec

I've been building Infusion, a generator that turns OpenAPI specs into Elixir SDKs, and the first SDK I've published with it is for Twilio's core REST API: https://hex.pm/packages/twilio

```elixir

{:ok, message} =

Twilio.Messages.create(to: "+15558675310", from: "+15017122661", body: "Hello from Elixir")

```

Why: Twilio has no official Elixir SDK. ex_twilio has served the community for years, but its last release was in April 2024, and since it's written by hand, new endpoints arrive only when someone adds them. This one is generated, so it covers all 197 operations of the 2010-04-01 API, and a GitHub Action regenerates it from Twilio's spec every day and opens a PR when the API changes.

What's in it:

- Docs and typespecs on every function, structs for every response

- The account SID from config, and `account_sid:` on any call for subaccounts

- `list_all` functions that stream every page lazily

- Typed errors with Twilio's error code; retries on connection errors, 429 and 5xx

- `Twilio.Webhook.valid?/4` for `X-Twilio-Signature`, checked against twilio-python on 2,000 random requests and on real webhooks

- `Twilio.AccessToken` for the Voice, Video and Conversations client SDKs

- Built on Req, so `Req.Test` works for stubbing

Not covered yet: Verify, Conversations, Messaging Services and Twilio's other product APIs, which are separate specs. If you use Twilio from Elixir, which one would you want next?

Bug reports and naming complaints welcome: https://github.com/mandar1045/twilio

8 Upvotes

4 comments sorted by

1

u/Flashy_Cold9139 10d ago

How difficult is it to do this for Telnyx?

3

u/Reckless_Dev1045 10d ago

Telnyx publishes an OpenAPI spec, so it should mostly be one command: mix infusion.gen <spec url> --name Telnyx, plus a bit of config for auth. I haven't tried it on their spec yet, so I can't promise it's clean. If you give it a go and something breaks, open an issue and I'll fix it. Or I can try it myself this week and let you know.