0.01
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
ActionMailer heavily-inspired gem to handle SMS/Text Messages
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 0.1.5
~> 10.0
~> 3.0
~> 2.1.0

Runtime

>= 4.0.0
>= 4.0.0
>= 4.0.0
>= 5.1.2
 Project Readme

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)