Coder Social home page Coder Social logo

visualitypl / textris Goto Github PK

View Code? Open in Web Editor NEW
130.0 130.0 63.0 174 KB

Implement texter classes for sending SMS messages in similar way to how e-mails are sent with ActionMailer-based mailers. Take advantage of e-mail proxying and enhanced phone number parsing, among others.

License: MIT License

Ruby 90.88% JavaScript 0.02% CSS 1.70% HTML 7.40%

textris's People

Contributors

b4k3r avatar kamilkowalski avatar karolsluszniak avatar kmanzana avatar konrad-glowacki avatar marahin avatar monsieurdart avatar nowakov avatar papa-whisky avatar philnash avatar ronin avatar sakirtemel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textris's Issues

Amazon SNS support

Hi!! Thank you for the wonderful gem.

By the way, do you have any plans for Amazon SNS?
If you don't have plan. Can I make PR for Amazon SNS?

Alphanumeric support for Twilio

Hi!

Realy trying to use alphanumeric Id with Twilio and can't make it work. My quest is that Phony.normalize is passing just a + and not the string. Any thoughts?

Defaults don't get inherited from a base

Defaults don't get inherited from a base:

class ApplicationTexter < Textris::Base
  default from: 'Acme Corp'
end
class SomethingTexter < ApplicationTexter
end

ApplicationTexter.with_defaults({}) # => {:from=>"Acme Corp"}
SomethingTexter.with_defaults({}) # => {}

I guess class_attribute can be used similar to how ActionView::Layouts implements layout? _layout class attribute definition, layout method

Not compatible with Rails 5

Not compatible with Rails 5

Bundler could not find compatible versions for gem "actionmailer":
  In Gemfile:
    rails (~> 5.0.0.beta3) was resolved to 5.0.0.beta3, which depends on
      actionmailer (= 5.0.0.beta3)

    textris (~> 0.4.1) was resolved to 0.4.1, which depends on
      actionmailer (~> 4.0)

Declaring a Default Queue

Is it possible to implement a default queue, similar to ActionMailer or Textris's ownfrom value? I don't use the :textris queue and manually setting a queue on every delivery is quite repetitive.

Something like this:

class NotificationTexter < Textris::Base
  default queue: "notifications"

  def cool_update(user)
    ... 
  end
end

Another nice option would be be able to override the default :textris queue in an optional initializer. For example, this is how Rollbar approaches this issue:

# config/initializers/rollbar.rb
Rollbar.configure do |config|
  config.use_sidekiq 'queue' => 'low' 
end

This is a fantastic gem overall, but being able to customize some fairly basic defaults (i.e. #29) would make it much cleaner to incorporate into existing Rails apps.

Twilio configuration

Looks like this "pre-configuration" method no longer works in twilio-ruby 5.3.0:

Twilio.configure do |config|
config.account_sid = 'some_sid'
config.auth_token = 'some_auth_token'
end

It was removed from lib/twilio-ruby.rb in this commit:
twilio/twilio-ruby@038a3f9

Request: Ability to cancel/abort a send.

I couldn't find a good way of cancelling a send once a job has been queued. Rails mailers have a self.message.perform_deliveries = false flag which can be set on the message.

Basically what I'd like to do is have my code always queue the text jobs, but then when the job is actually performed in the background, be able to do some logic checks and prevent delivery of the message if some case is true. For example, if the job is running at 9am, do not send the text to people in area codes 818.

Any way of doing this easily?

I got There was an error while trying to load the gem 'textris'. (Bundler::GemRequireError)

Hi,

I am trying to use textris on my rails app. But I got "There was an error while trying to load the gem 'textris'. (Bundler::GemRequireError)" error.

This is the full error:

Colins-MacBook-Pro:rentlord Ryzal$ rails s
/Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'textris'. (Bundler::GemRequireError)
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
    from /Users/Ryzal/Desktop/Sites/rentlord/config/application.rb:8:in `<top (required)>'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /Library/Ruby/Gems/2.0.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

Any help? Thanks!

template_path support?

Does this gem support a template_path option ร  la Rails ActionMailer? So instead of putting all the <texter_name> views under app/views it can be anywhere like app/views/texters.

I tried emulating the ActionMailer way like so:

class UserTexter < Textris::Base
  default from: 'Our Team <+1 500-555-0006>'
  default template_path: "texters/#{name.underscore}"
  ...
end

But it still looks exclusively under app/views.

Use case for this would be to separate texters from mailers and every other views under app/views to allow view organization like the following:

  • app/views/mailers
  • app/views/texters

Queue name doesn't change

The API for changing queue name doesn't work:

AccountTexter.welcome(user).deliver_later(queue: :sms_notifications)

Rails 6 compatibility

The render_anywhere gem (which this one depends on) doesn't work in Rails 6, since it mutates view_paths, which is no longer allowed.

It doesn't look like render_anywhere is actively maintained, so this is unlikely to be fixed there. On the upside, render_anywhere is a small gem.

Test against Rails 5

Right now, due to the lock file being included, this will only run against Rails 4. We should test against Rails 5 and adjust CI so that tests can be run against both 4 and 5 for the time being.

New version of twilio-ruby coming soon

I just wanted to let you know that there is a new major version of the twilio-ruby gem on it's way soon. This new version is not backwards compatible with version 4 or below.

Since Textris, in production, doesn't depend on twilio-ruby it is worth testing this with versions 3 (which is the development dependency here), 4 and 5 (currently rc18).

I can take a look at this soon, but things are really busy for me right now, so I thought I'd call it out here in case anyone else can look.

unit test dependency

If you run just mail_spec.rb tests, there is a failure. If you run all tests, they pass.

On current master branch this happens:

[master][~/Projects/textris]$ rspec spec/textris/message_spec.rb
.............F.

Failures:

  1) Textris::Message#content lazily renders content
     Failure/Error: expect { message.content }.to raise_error(ActionView::MissingTemplate)
     
       expected ActionView::MissingTemplate, got #<NameError: uninitialized constant RenderAnywhere::RenderingController::Rails> with backtrace:
         # /Users/keltonmanzanares/.rvm/gems/ruby-2.3.1/gems/render_anywhere-0.0.12/lib/render_anywhere/rendering_controller.rb:25:in `initialize'
         # /Users/keltonmanzanares/.rvm/gems/ruby-2.3.1/gems/render_anywhere-0.0.12/lib/render_anywhere.rb:28:in `new'
         # /Users/keltonmanzanares/.rvm/gems/ruby-2.3.1/gems/render_anywhere-0.0.12/lib/render_anywhere.rb:28:in `rendering_controller'
         # /Users/keltonmanzanares/.rvm/gems/ruby-2.3.1/gems/render_anywhere-0.0.12/lib/render_anywhere.rb:21:in `set_instance_variable'
         # ./lib/textris/base.rb:81:in `block in set_instance_variables_for_rendering'
         # ./lib/textris/base.rb:80:in `each'
         # ./lib/textris/base.rb:80:in `set_instance_variables_for_rendering'
         # ./lib/textris/base.rb:49:in `render_content'
         # ./lib/textris/message.rb:47:in `content'
         # ./spec/textris/message_spec.rb:162:in `block (4 levels) in <top (required)>'
         # ./spec/textris/message_spec.rb:162:in `block (3 levels) in <top (required)>'
     # ./spec/textris/message_spec.rb:162:in `block (3 levels) in <top (required)>'

Finished in 0.06978 seconds (files took 1.21 seconds to load)
15 examples, 1 failure

Failed examples:

rspec ./spec/textris/message_spec.rb:154 # Textris::Message#content lazily renders content

[master][~/Projects/textris]$ rspec spec                        rvm:ruby-2.3.1 
.......................................................................

Finished in 0.28365 seconds (files took 1.15 seconds to load)
71 examples, 0 failures

Current Ruby version is ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]

To number not valid

Hi,

I'm able to send SMS this way, but weird thing, it only sends to one user, even if I have 3 users.

My method in User.rb

def send_daily_sms(user)

    @user = user

    # put your own credentials here 
    account_sid = 'AC2556499574e7111844811bff28e73061' 
    auth_token = '0593dd8cc063cfbe704bc73a8f83fbba' 

    # set up a client to talk to the Twilio REST API 
    @client = Twilio::REST::Client.new account_sid, auth_token 

    @client.account.messages.create({
        :from => '+14234350632', 
        :to => '+' + @user.phone, 
        :body => 'SMS journalier',  
    })
  end

My task :

task :email_sender_daily => :environment do |_, args|
  User.find_each do |user|
    user.send_daily_sms(user) if user.daily_sms == true && user.phone.present?
  end
end

So I decided to use the gem Textris to see if using this would work.

My UserTexter :

class UserTexter < Textris::Base
  default from: "Our Team <+14234350632>"

  def send_daily_sms(user)
    @user = user
    phone = "+" + @user.phone
    puts phone
    text :to => phone
  end
end

The thing is, I have this in the log :

+41798352547
rake aborted!
Twilio::REST::RequestError: The 'To' number 41798352547 is not a valid phone number.

But as you can see, the number printed in the log is right, and I was doing quite the same when I was using the method in User.rb (it was sending SMS then, but only to one user).

Don't know what to do.

Question: Clean way to call Texter when User phone number is not a required field?

Perhaps this is a nit-pick, but currently we always have to do something like:

UserTexter.welcome(user).deliver_later if user.phone?

Since the call to #welcome will fail without an E.164 compliant phone number, we cannot handle this at the job level. Also, returning nil from #welcome such that we now call:

UserTexter.welcome(user)&.deliver_later

doesn't seem like much of an improvement. I'm wondering if this is consistent behavior in terms of the API for ActionMailer, and we just don't have to deal with this case because email is a field that does have a not-null constraint. What is the way that you would imagine handling calling Texter methods in an app where phone is allowed to be null?

parse_content removes newlines

parse_content is currently removing newlines. Newline is acceptable in an SMS message. Actually I don't think it's a responsibility of textris to do any transformation on the content.

Shortcodes don't work

Hello,
Great gem! I'm liking it so far. I'm curious if short codes are supported? I'm using this for a soon to launch app and getting this error:

Twilio::REST::RequestError: The 'From' number + is not a valid phone number, shortcode, or alphanumeric sender ID.

When trying with 89045 format style of number as we have a short code we are trying to send messages from. Any thoughts or ideas here?

I'd posit that phone_with_plus(phone) tries to add a + to it.

If I add a '+89045' I get the + error. If I try to pass in '89045' I get an error that the from is blank.

Any thoughts or guidance here?

Thanks!

`Textris::Delivery::Twilio#deliver` Ruby 3 Compatibility Issue

Textris::Delivery::Twilio#deliver#20 isn't compatible with Ruby 3.0+ as in Ruby 3.0, the positional and keyword arguments have been separated. More on this is available here: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

I have created a quick PR that fixes the issue here: #71

However, I'm unsure if this is the best way doing this, is there a better way?

Any help/feedback on this will be greatly appreciated.

Many Thanks,
Luke

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.