alexford / twilito Goto Github PK
View Code? Open in Web Editor NEWA tiny, zero dependency Ruby helper for sending text messages with Twilio ๐ฌ
Home Page: https://twilito.netlify.app
License: MIT License
A tiny, zero dependency Ruby helper for sending text messages with Twilio ๐ฌ
Home Page: https://twilito.netlify.app
License: MIT License
Hi there, love the lightweight simplicity of this gem!
Twilio's Messaging Service allows for passing a messaging_service_sid
parameter in place of from
. The Messaging Service then matches the given recipient with a phone number from a corresponding sender pool. (docs)
It seems this is not presently possible, since from
is a required parameter. Perhaps from
could be conditionally required unless messaging_service_sid
is present? Is there another workaround that I may be missing here?
Thanks! โ๏ธ
Ruby 2.4.9
result = Struct.new(:success?, :errors, :sid, :response, keyword_init: true) {}
=>
TypeError: {:keyword_init=>true} is not a symbol
https://stackoverflow.com/questions/15055852/how-to-change-the-default-value-of-a-struct-attribute
$ irb
2.4.9 :001 > Result = Struct.new(:success?, :errors, :sid, :response, keyword_init: true) do
2.4.9 :002 > def self.success(**args)
2.4.9 :003?> new(success?: true, **args)
2.4.9 :004?> end
2.4.9 :005?>
2.4.9 :006 > def self.failure(**args)
2.4.9 :007?> new(success?: false, **args)
2.4.9 :008?> end
2.4.9 :009?>
2.4.9 :010 > def errors
2.4.9 :011?> to_h[:errors] || []
2.4.9 :012?> end
2.4.9 :013?>
2.4.9 :014 > def data
2.4.9 :015?> JSON.parse(response_body || '{}')
2.4.9 :016?> end
2.4.9 :017?>
2.4.9 :018 > private
2.4.9 :019?>
2.4.9 :020 > def response_body
2.4.9 :021?> return nil unless to_h[:response]&.respond_to?(:read_body)
2.4.9 :022?>
2.4.9 :023 > to_h[:response].read_body
2.4.9 :024?> end
2.4.9 :025?> end
TypeError: {:keyword_init=>true} is not a symbol
A = Struct.new(:a, :b, :c) do
def initialize(a:, b: 2, c: 3)
super(a, b, c)
end
end
Twilito should be easy to mock/stub/double in tests as is, but some examples of this in the README may be useful because I consider ease of testing a benefit of using Twilito vs the full Twilio gem.
Also (and maybe this is a separate issue), including some little helpers could be nice. For example, in RSpec it'd be cool to be able to something like this:
expect { subject }.to send_sms(body: 'foo')
(The plan here needs fleshed out! Perhaps Twilito needs to be put into some kind of test mode for this to keep track of messages it would have sent rather than actually POSTing)
GitHub Actions-based CI has started to fail with this message:
Example failure: https://github.com/alexford/twilito/actions/runs/639173381
The .success
and .failure
class methods (helpers that delegate to initialize
with the success:
keyword argument set), in Twilito::Result
are throwing warnings in Ruby 2.7.0.
This is just noisy now but will break in Ruby 3.0
I messed around with this a bit but wasn't able to get the warnings to go away quickly. Maybe it's just too early in the morning...
/home/runner/work/twilito/twilito/lib/twilito/result.rb:10: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
39
/home/runner/work/twilito/twilito/lib/twilito/result.rb:5: warning: The called method `initialize' is defined here
/home/runner/work/twilito/twilito/lib/twilito/result.rb:14: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
39
/home/runner/work/twilito/twilito/lib/twilito/result.rb:5: warning: The called method `initialize' is defined here
It's possible I'm just doing something fundamentally weird here and this is a sign that it should be simplified or done differently.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.