๐ฉ Send SMS with Ncloud Sens
MIT License
Send your SMS with Ncloud Sens in Ruby.
ํ๊ตญ์ด ๋ฌธ์๋ฅผ ์ฝ๊ณ ์ถ๋ค๋ฉด, ์ฌ๊ธฐ๋ฅผ ํด๋ฆญํ์ธ์
Add this line to your application's Gemfile:
gem 'sens_sms'
Then execute:
$ bundle
Finally, run the generator:
$ rails generate sens_sms:install
At this point, you can find a sens_sms configuration file located at YOUR_PROJECT/config/initializers/sens_sms.rb
.
require 'sens_sms'
SensSms::Client.configure do |config|
config.access_key = ENV['NCLOUD_ACCESS_KEY']
config.secret_key = ENV['NCLOUD_SECRET_KEY']
config.service_id = ENV['NCLOUD_SERVICE_ID']
end
You can set your Ncloud access keys here, but we recommend to use Environment Values. Generating access keys guide is here.
Install the gem:
$ gem install sens_sms
If you plan to use sens_sms gem in plain Ruby project,
then you should call require 'sens_sms'
and SensSms::Client.configure
block
to set access keys before calling deliver
method like rails generator do it.
# SMS
SensSms::Client.new
.deliver(type: :sms,
from_number: '01012345678',
to_numbers: '01098765432',
message: '์ ์ธ๊ณ์ ์๋ ค์ง ํญ๊ท์ ์ข
๋ฅ๋ 17์ข
ํน์ 18์ข
์ด๋ค.')
# LMS
SensSms::Client.new
.deliver(type: :lms,
from_number: '01012345678',
to_numbers: '01098765432',
title: 'ํญ๊ท',
message: '์ ์ธ๊ณ์ ์๋ ค์ง ํญ๊ท์ ์ข
๋ฅ๋ 17์ข
ํน์ 18์ข
์ด๋ค. (์ ํธ๋ฅธํญ๊ท๊ณผ ํฐ๋ ๊ฐํญ๊ท์ด
์๋ณ๋๋์ง ์๋์ง์ ๋ฐ๋ผ ๋ฌ๋ผ์ง๋ค.) ๋ชจ๋ ํญ๊ท ์ข
์ ๊ณ ํฅ์ด ๋จ๋ฐ๊ตฌ์ด๊ธฐ๋ ํ์ง๋ง,
ํต๋
๊ณผ ๋ฌ๋ฆฌ, ๋จ๊ทน๊ณผ ๊ฐ์ด ์ถ์ด ๊ธฐํ์์๋ง ์์ํ์ง๋ ์๋๋ค. ์ค์ ๋ก๋ ๋ช๋ช ์ข
๋ง์ด
๊ทน์ง๋ฐฉ์ ์ฐ๋ค. 3์ข
์ ์ด๋ ์ง๋ฐฉ์ ์ด๋ฉฐ, ๊ทธ ๊ฐ์ด๋ฐ ๊ฐ๋ผํ๊ณ ์ค ์ ๋์ ์ฌ๋ ํ ์ข
์ ๋จน์ด๋ฅผ
์ฐพ๋ค๊ฐ ์ ๋๋ฅผ ๊ฑด๋๊ธฐ๋ ํ๋ค. ๊ฐ์ฅ ํฐ ์ข
์ ํฉ์ ํญ๊ท์ผ๋ก, ๋ค ์๋ผ๋ฉด ํค๊ฐ ์ฝ 1.1๋ฏธํฐ,
๋ฌด๊ฒ๊ฐ ์ฝ 35ํฌ๋ก๊ทธ๋จ ์ด์์ด๋ค. ๊ฐ์ฅ ์์ ์ข
์ ์ ํธ๋ฅธํญ๊ท์ผ๋ก, ํค๋ ์ฝ 40์ผํฐ๋ฏธํฐ์
๋ชธ๋ฌด๊ฒ๊ฐ 1ํฌ๋ก๊ทธ๋จ์ ๋ถ๊ณผํ๋ค. ์ผ๋ฐ์ ์ผ๋ก ํญ๊ท์ ๋ฉ์น๊ฐ ํด์๋ก ์ด์ ์ ๋ณด๊ดํด์
์ถ์ด ์ง๋ฐฉ์ ์ด๊ณ , ์์ ํญ๊ท๋ค์ ์จ๋๋ ์ฌ์ง์ด ์ด๋์์ ๋ฐ๊ฒฌ๋๋ค.')
After calling configure method, use SensSms::Client.new.deliver
with below arguments.
You can use from_number
key to set sender number registered at Ncloud SENS console.
You can use to_numbers
key to set receiver number.
Also to_numbers
can be set multiple numbers with Array type. (eg. ['01012345678', '01009876543']
)
You can use type
key to choose message type.
SMS can send short message with up to 80 bytes and this type cannot use title. However, sending title key will do not raise any error, it'll be just ignored.
LMS type can send title and super long text message with up to 2,000 bytes.
Basically, This key is optional used by LMS message type for title. Of course, this key can be used in SMS message type, but nothing will be happened.
Text message.
Bug reports and pull requests are welcome.
The gem is available as open source under the terms of the MIT License.