Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

action_short_message

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

action_short_message

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

ActionShortMessage

ActionShortMessage reference to dballona/actionmessage, is heavily-inspired on ActionMailer. It's a gem for sending SMS/Text messages like we do for sending e-mails on ActionMailer.

Setup

Install it using bundler:

# Gemfile
gem 'action_short_message'

Configuration

Place this on your environment file or application.rb


# Setting logger, default is Rails.logger
config.action_short_message.logger = Rails.logger

# Setting short message service provider, default is setting.
#
# Highly recommended place this on the environment files, and set 
# development sms_provider to :test it can save your money
config.action_short_message.sms_provider = :test 


SMS Provider

Default provider is test, I also made a provider, use Mitake(山竹簡訊) api. You can add mitake_sms in Taiwan 🇹🇼

you also can create your provider, by implement ActionShortMessage::SMSProviders::Base and add provider follow by ActionShortMessage::Base.add_provider(symbol, YourProvider, provider_setting)

Usage

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

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

  # Inline message 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, message: 'Inline message')
  end
end

Views

If you want to use template, add this file to app/view/messenger/{your_messenger_name}/{method_name}.erb

Welcome, <%= @name %>!

Callbacks

You can specify callbacks using before_action and after_action for configuring your messages.

class WelcomeMessenger
  before_action :set_default_message
  after_action :log_message

  private

  def set_default_message
    ...
  end

  def log_message
    ...
  end
end

And to send is really simple!

name = 'John Doe'
phone = '0987654321'

# 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

FAQs

Package last updated on 24 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc