GithubHelp home page GithubHelp logo

actionmessage's Introduction

ActionMessage

ActionMessage is heavily-inspired on ActionMailer. It's a gem for sending SMS/Text messages like we do for sending e-mails on ActionMailer. Pull requests are more than welcome!

Gem Version Build Status codecov Code Climate

Setup

Install it using bundler:

# Gemfile
gem 'actionmessage'

If you're using Rails, place this on your environment file or application.rb

require 'action_message/railtie'

config.action_message = {
  # sender in international format you can also pass an array and it will
  # shuffle and randomly pick one number.
  from: "+11231231234",

  # adapter information. Right now we only support Twilio.
  adapter: { 
    name: :twilio,
    credentials: {
      account_sid: 'MY TWILIO ACCOUNT SID'.freeze,
      auth_token: 'MY AUTH TOKEN'.freeze
    }
  }
}

Usage

In order to generate your message class, you can either place this code under app/messages/welcome_message.rb or just use our generators by running the following command: rails g message Welcome send_welcome_sms

class WelcomeMessage < ActionMessage::Base
  def send_welcome_sms(name, phone_number_to_send_message)
    @name = name
    sms(to: phone_number_to_send_message)
  end

  # Inline body example, body parameter has preference compared
  # to a text.erb template.
  def welcome_with_inline_body(name, phone_number_to_send_message)
    @name = name
    sms(to: phone_number_to_send_message, body: 'Inline body!')
  end

  # While on development environment, you can use debug: true to
  # prevent sending SMS and spending funds on your Twilio account.
  def welcome_with_debug_mode(name, phone_number_to_send_message)
    @name = name
    sms(to: phone_number_to_send_message, debug: true)
  end
end

Define your views under your view path, such as: app/views/welcome_message/send_welcome_sms.text.erb

Welcome, <%= @name %>!

And to send is really simple!

name = 'John Doe'
phone = '+11231231234'

# To send right away:
WelcomeMessage.send_welcome_sms(name, phone).deliver_now

# To send through a background job
WelcomeMessage.send_welcome_sms(name, phone).deliver_later

Interceptors

In order to prevent sending messages to a specific number or containing any specific text on it's body you can use Interceptors:

# You can use strings (exact comparison)
ActionMessage::Interceptor.register(to: 'number I want to prevent sending messages')

# Regular expressions
ActionMessage::Interceptor.register(body: /something innapropriate/i)

# Pass Multiple arguments on the same call
ActionMessage::Interceptor.register(to: '+11231231234', body: /anything/i)

actionmessage's People

Contributors

carlosramireziii avatar dballona 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

Watchers

 avatar  avatar

actionmessage's Issues

Add engine for receiving hooks from the adapters

Do you not find most of the work associated with twilio etc are setting up state machines and database layers for the sms/call states? In my experience the "send" portion of the work is very small compared to the data tracking and for twilio for instance setting up hooks to either get the delivery status or polling to do so.

I think it for sure deserves probably an engine to be mounted at routes, and persisting it out (even for interceptions for invalid numbers, as you suggested). that’s actually a huge feature, and VERY nice to have.

probably, something like

# on routes.rb
mount ActionMessage::Statistics => '/sms'

This engine would define two routes, one for hooks for the adapters to post messages into (such as Twilio). and the other one for statistics (more on that the statistics part on another github issue);

we’d probably have a module to include on the tracker model under the app for Mongoid, and a generator for SQL databases (generates both migration and model);

and on the hook action, we’d record every single interaction out the adapters send for us under that model. Would be basically plug and play.

Statistics screen for the engine

As described on #13

# on routes.rb
mount ActionMessage::Statistics => '/sms'

This engine would define two routes, one for hooks for the adapters to post messages into (such as Twilio). and the other one for statistics;

we’d probably have a module to include on the tracker model under the app for Mongoid, and a generator for SQL databases (generates both migration and model);

and on the statistics action, we’d show statistics that are common between adapters, such as delivery status, amount sent by date, amount received.

Basically consists on building something next to Sidekiq::Web engine on this interface.

Add more ruby versions on CI

Think about adding more ruby versions:

  • More CRuby versions
  • JRuby
  • Rubinius

I can help with something like that

Formatting errors per adapter

Some adapters may accept different characters as the phone to receive message.

We should create error specializations (or maybe just log errors?) for each one of the Adapter classes, with correct messages if something goes wrong, e.g.:

Twilio:
21211: Invalid 'To' Phone Number
21401: Invalid Phone Number
21407: This Phone Number type does not support SMS
21614: 'To' number is not a valid mobile number

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.