How do you receive SMS from Nexmo using Nexmo gem rails

I am using Rails 3.2.8 and am considering using neximo. Neximo gem does not seem to provide methods for receiving SMS messages. How to receive SMS messages? Create a controller with actions to respond to a GET? I am relatively new to rails, looking for pointers to the approach.

  • how do i set up a route.
  • I assume that I don’t need to output anything as soon as I receive the message, so I don’t need a template, so I do this bypassing the rendering?

Any pointer or help would be appreciated.

+4
source share
3 answers

Well, it looks like you will want to use the Ruby library created for Nexmo .

Essentially, you should put this sample code:

nexmo = Nexmo::Client.new('...API KEY...', '...API SECRET...') response = nexmo.send_message({ from: 'RUBY', to: '...NUMBER...', text: 'Hello world' }) if response.success? puts "Sent message: #{response.message_id}" elsif response.failure? raise response.error end 

.. inside the action in your controller. Let's say this is your TextsController , and you put it under the create action. So in your config/routes.rb put something like:

match "/sendtext" => "texts#create"

Then you just hit mydomain.com/sendtext and the team should fire.

+3
source

It turned out to be easy. First create a controller, say you call the controller "foo"

 rails generate controller foo 

in the file foo_controller.rb add the following:

 class SmsesController < ApplicationController def getmessage text_from_phone_no = params[:msisdn] text_body = params[:text] # here you can extract more values from parameters as described in nexmo docs. render :nothing => true # this will supply the needed http 200 OK end end 

In routes.rb add the following:

get "foo / getessage"

then in Nexmo specify the URL to receive messages as:

your-domain.com/foo/getmessage.com

That is all you have done.

+2
source

I'm not sure if there is any helper in the Ruby library to decode the response, but the incoming message is just an HTTP GET or POST for any URL that you configure for the number (in the Nexmo toolbar).

Here is the documentation for incoming messages .

(Disclaimer: I'm doing a bit of developer evangelism for Nexmo.)

+1
source

Source: https://habr.com/ru/post/1438025/


All Articles