Hemanth.HM

A Computer Polyglot, CLI + WEB ♥'r.

SMS Service With Firefox OS

| Comments

Assume a senario, a course booking service which need an SMS feature with the below work flow:

  • A customer sent a message of the format: <name> <course_name> <course_time> <number_of_tickets>

  • We need to reply to the sender with a thank you message of the format: Thank you <name>! Your booking (<number_of_tickets tickets) for <course_name> at <course_time> is confirmed.

This can be easily achived with the below code in fxos:

1
2
3
4
5
6
7
navigator.mozMobileMessage.onreceived = (sms) => {
   let cust = sms.message.sender,
   [name,courseName,courseTime, tcktCnt] = sms.message.body.split(' '),
   msg = `Thank you ${name}! Your booking (${tcktCnt} tickets) for ${courseName} at ${courseTime} is confrimed.`

   navigator.mozMobileMessage.send(cust, msg);
 }

Well, this is just a snippet, you would have to do a bit more to make it a service, for a quick hacky way, you could run the offical SMS app in debug mode and execute this snippet in the browser console.

There might be more better ways to do it, but this was one of easiest ways for me at a hackathon.

Comments