RoR + SMS: Rails web app architecture to send/receive SMS? - ruby-on-rails

What web app architecture works well receiving/sending SMS text messages? By "architecture, I mean specific architecture, not generally, such as MVC.
Background: I'm building a web app that receives queries from/sends answers to cell phones. The app design (and business model) expects to communicate with cell devices via SMS text messages. IOW: There is no MVC web page "view". The cell phone screen is effectively the "view".

I would question whether this is really a web application. If the view layer is SMS, you don't have to use the internet as a transport, you could use hardware to connect to the cell phone network.
If you are thinking of using a commercial http/sms gateway, there is a good article on using the Ruby Clicktell gem from a Rails application. Seems like a good route to try.

This depends on how you will be receiving and sending the SMS messages.
There is a specific Short message protocol (SMPP - http://en.wikipedia.org/wiki/SMPP).
For that you will need an SMPP server.
If you are using a one of the various SMS over HTTP providers (such as Clickatell - http://www.clickatell.com), then a web framework such as RoR is fine as both the sending and receiving of SMS messages are actually web requests.
In this case your system view is the HTTP response to the gateway, not the cellphone screen. There are actually quite a few steps involved:
Cellphone -> Cellular Network -> Gateway -> Your Service and the reply: Cellphone <- Cellular Network <- Gateway <- Your Service

I've made one of these before using rails. I created a budget tracker I could send commands to with my cell phone. I used it to create a list of items i needed to buy/take care of on the upcoming paycheck. When the check came in, I would send commands to mark each item off the list. I included commands to query a list as well. The commands looked something like "lc mar4" to create the fourth paycheck in march's budget list. Once a list was created, I could send commands without specifying the list and I made the script just apply the command to the last list if no list was specified and crunch down the other arguments. "la court 50 p" would add too the mar4 list an item named "court" with a value of 50 and a tag "p" which I called pending. When I took care of court that friday, I could send "lu court 50 d" which would update the court item with the same value with the tag "d" for done. I had a command called "lp" which would print the current list. "lp d" would print all the "d" tagged items on the current list. "lsum p" would print all the pending items on the current list.
I made an empty rails app. Made my database schema and my models but had no controllers. I had a script in scripts that included a pop/ssl library i found somewhere to download email from a gmail account i had setup for this. From then on it was pretty easy, just check the new messages for each message make sure it came from my cell phone and parse the message and optionally send back a response. (I had programmed that email address into my cellphone, and sent text commands to that email address). I added a cron job and set it to run every minute.
I don't know what that architecture is, but its basically a service that queries a 3rd party and does different things dependent on the response. If you did true SMS with shortcodes, I'll let you know now that I think there is a sizeable investment necessary to do those for real. Might be easier to start develop with email text messaging through sms gateways.
I'm not saying this is the best way to do it by far, It would have been cooler to have had the messages "pushed" to me instead of checking every minute, but hey I just wanted to balance my budget with my phone.

Related

Options for combining multiple Amazon Lex bots

I work in a large enterprise where multiple teams are developing Lex bots (on separate accounts). Each bot supports a different domain or application,. In some cases, it would be nice for a single user interface to ask a question without needing to know which bot to ask. Is there a way to federate bots, or to forward un-recognized intentions to 'backup' bots?
I feel like what I really want to do is treat each bot as a skill is treated in Alexa, except I'm in the position (through entitlements) to know which 'skills' would be appropriate for a given user.
The answer here is that you would need to develop a custom application that delivers a user's input to each of your company's array of bots.
You'd need to look at the NLU Confidence score from each Bot's response to decide which response is the most accurate to return to the user. Would also be worthwhile keeping some state in your app to remember which Bot the user is currently interacting with and defaulting to that Bot for successive user inputs. Should you reach a point where the confidence score is low, it might present a signal to you to test the user's input across the other Bots.
What you'll need to be aware of here is that your costs will increase with each additional Bot that you add. So, assuming you have 5 area-specific Bots, one inbound message from your user could result in 5 Lex calls. As you start moving into significant volumes of interactions, this could start proving to be an obstacle.
An alternative would be to use a custom fallback intent to invoke a Lambda function that calls your Bot orchestration function. Assuming that you're able to find the correct Bot to handle the user's query, you'd need to remember that so succesive messages now get routed to that Bot.

Twilio custom caller ID

On a ride booking app, it is required communication between driver and user.
Now the case, if user A contacts the driver via website or app, call or sms can be achieved via Twilio, we don't want to expose their contact numbers to each other.
If three users A, B and C contacts the driver and driver has no app installed, in fact the driver wants call back and sms reply. How the driver can reach users on Caller ID.
There could be large number of users and we can't buy separate twilio number for each user.
Please advise the solution.
How many users are likely to need to contact each individual driver at any one time? Not many I wouldn't think.
Buy 10 Twilio numbers, assign them incrementally as users call/SMS their driver and save the assignment for user/driver numbers in your database.
If the driver calls/SMS a number in response query the database and route the call/SMS to the user it was assigned to when they called the driver.
Recycle the 1st assignment once the 11th user calls/SMS the driver, rinse and repeat.
Twilio developer evangelist here.
In order to maintain anonymous communications in this way you need as many numbers as the maximum number of relationships one person in your system has. The best explanation of this is in this article on masked text messaging with Twilio (though it applies to calls too).
Your comment on miknik's answer suggests you want to keep these relationships alive forever. This is not the way that most services build out this feature. They normally give a particular length to the relationship, Uber for example will recycle the phone number a number of minutes after a ride ends.
If you are looking for an easier way to manage this kind of number pooling and masking, check out Twilio Proxy, it handles a lot of the logic for you. It is still in developer preview right now, but you can apply for early access.

Twilio Application to call another person if one call fails

I am studying twilio's auto calling functionality for the one of our client.
Requirements:
We are handling software system of our client. And when ever there is error in
the system I need to call specific persons.
I could do above function easily on testing environment using php. But In actual scenario,
I want call on multiple number like if one person is not receiving call I must get call
on second number, third number and so on until one person receives call and understands error.
For the above functionality I have studied "Call Screening " example from site and also
communicate to support person but I didn't get exactly from the conversation.
When I call attempt_call.php from my browser I am getting xml output on browser only not any call.
Please guide me if any ready example is there that can solve my problem.
Thanks and best regards.
Piyush Merja
CallScreening didnt work for me..
I have called to one person and checked for its status if its completed then process terminated or continued to another person

How to mark IMAP message as fetched?

I am working on PHP project that should fetch emails from IMAP server, and store them in local database.
Same IMAP server can be used by other email clients, like outbox and so on.
The problem is how to know which messages I already fetched, and which I didn't? I am thinking to use search by datetime, but is it reliable(I would have cronjob, that would access user mail box every minute, and check for emails, but not sure if datetime can cause some issues, for example in case when at almost same time arrive short message and message with big attachment).
I was thinking about system tags, but user can modify them via email client, so I can rely on them, and don't want to modify them and confuse client.
Next I was thinking about custom tags, but not all IMAP servers support them(and our software need to be flexible as much as possible).
Any good idea how I could solve this problem?
Keep track of the currently highest synced UID of the folder you are syncing, and verify that the UIDVALIDITY value of the folder match.
Unique identifiers are assigned in a strictly ascending fashion in the mailbox; as each message is added to the mailbox it is assigned a higher UID than the message(s) which were added previously. Unlike message sequence numbers, unique identifiers are not necessarily contiguous.

Can an email be printed as soon as it enters the Inbox?

We are working on an online food ordering application. When the user orders something from any restaurant, an email is sent to the restaurant's email address mentioning the order details. However, our client wants that an order print out should be generated automatically as soon as a new order is received.
Is it feasible using ROR? If not, any alternate solution to the problem?
When my group wrote something like this we went a little lower tech, and had the system generate a fax and send it to a fax machine at the restaurant. Of course, that's mainly because this was a system working across many restaurants, with disparate IT infrastructures, and the one thing they had in common was each had a fax machine.
I would figure this could be done in 1 of two ways:
1- Outlook event-- Outlook has the ability to set up 'rules', one of which I think allows printing.
2- Create a script that runs every few minutes, checks the email (either through IMAP, or POP, depending on the account), and prints all of them out.
See this: http://ruby.about.com/od/tasks/a/pop3.htm for info on how to check POP3 mail with ruby on rails.
For printing, the links mentioned here seem useful: http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/504a616bf3e28057/ff6cb91462dfe961?pli=1
Ensure that you have 'from' or 'subject' filters setup, otherwise there will be a lot of spam printing.
You can use software to print your order automatically when email is received, it supports also print attachment like pdf, word, etc...
It is used by a lot of restaurant to print online order:
http://www.automatic-email-manager.com/

Resources