PHP Classes
elePHPant
Icontem

Better User Interaction with SMS Text Messages using the PHP dotGO Engine - PHP dotGo Engine package blog

Recommend this page to a friend!
  All package blogs All package blogs   PHP dotGo Engine PHP dotGo Engine   Blog PHP dotGo Engine package blog   RSS 1.0 feed RSS 2.0 feed   Blog Better User Interacti...  
  Post a comment Post a comment   See comments See comments (1)   Trackbacks (0)  

Author: Dave Smith

Posted on:

Package: PHP dotGo Engine

The DOTGO services can help sites interact with users communicating via SMS messages but to be truly interactive with our users, it is important to remember what we already have learned about them from previous interactions, even if they come back a week later.

Read this article to learn how to do just that by implementing our own engine to manage the logic tasks involved.




Contents

Introduction

Creating Another Engine

A Note on Sessions

Promotional Guidelines

Conclusion

SMS Web

Introduction

In the last article, we learned how to accept user <input> and <get/> it through the DOTGO service using the PHP dotGO Engine class. It still has some limitations though, since it is not very user friendly to require our users to enter their name each time they visit us.

Fortunately for us, the DOTGO service has stored our user's mobile number and <input> so that whenever they come back and visit our site again, we can access the information without having to request it over an over.

Creating Another Engine

The first thing we need to do is create another engine that can apply some logic. In this case, we are going to deal with the welcome message, so if we already know who the user is, we don't need to ask them who they are.

Using your favorite text editor, create a new text file named welcome.engine.php and add the following code to it...

<?php
//dotgo welcome response engine
//for use with dotgo class ver 0.1 beta
error_reporting(0);
session_start();
include_once( 'dotgo.class.php' );
$dotgo = new dotgo();
$dbConnected = $dotgo->dbConnect();
if( empty($dbConnected) ) {
    
  die('<message><content>There has been a connection error</content></message>');
    
}
if( empty($dotgo->dotData['user_name']) ){

  $response = array(
'responseType'=>'ctm',
'content'=>'<message>
  <content>Hello, what should I call you?</content>
  <input name="user_name">
<message>
<content>
Where to <get name="user_name"/>?<br/>
<a query="yoursite hello"/> Say Hello<br/>
<a query="yoursite news"/> Latest News<br/>
<a query="yoursite goodbye"/> Say Goodbye
  </content>
</message>
  </input>
</message>'
);

} else {

$response = array(
'responseType' => 'msg',
'content' => 'Hi '.$dotgo->dotData['user_name'].', enter #<br/>
<a query="yoursite notme"/> This is not me<br/>
<a query="yoursite hello"/> Say Hello<br/>
<a query="yoursite news"/> Latest News<br/>
<a query="yoursite goodbye"/> Say Goodbye'
);

}
echo $dotgo->showResponse( $response );
exit;
?>

Remember that you have to change yoursite to your actual site. Save the file and place it in the same folder where the dotgo.class.php file is located.

Now let's take a quick look at the code to see what we are doing here.

First we are including and instantiating the main dotgo class and establishing a connection to the database. Then we are applying our new logic to determine what our response to the user should be.

When we set up our user <input> in the previous article, we used the variable user_name to store our users response to our request wanting to know what to call them. DOTGO will pass all stored user input to an engine, where the main class will store it in the dotData array with the input variable as the key. So $dotgo->dotData['user_name'] will contain the stored name provided by our user, if one has been provided.

Our logic is first checking to see if we have a user_name, if not then the response is the custom message using the <input> element to get the users name. If we do have a user_name, then our response is a message element that welcomes them by that name and provides some choices.

Notice that we have added a 'notme' query to our standard welcome choices. The user can use this to change their stored name in the event that this isn't them. We will get back to this in a minute, first we need to make one more change to get this engine working.

Recall that the main dotgo class, dotgto.class.php, is where we define our default welcome message. If you have been following along through the other articles, it will look something like this...

 $this->defaultResponse = array(
  'responseType'=>'ctm',
  'content'=>'<message>
   <content>Hello, what should I call you?</content>
   <input name="user_name">
   <message>
    <content>
     Where to <get name="user_name"/>?<br/>
<a query="yoursite hello"/> Say Hello<br/>
<a query="yoursite news"/> Latest News<br/>
<a query="yoursite goodbye"/> Say Goodbye
</content>
    </message>
  </input>
</message>'
);

We need to change our default response to our new welcome engine so that it looks like this. Don't forget to change yoursite to you actual site.

 $this->defaultResponse = array(
'responseType' => 'eng',
  'content' => 'http://www.yoursite.com/dotgo/welcome.engine.php'
);

Now whenever our users send us a null request (a request without any keywords) the welcome engine will handle the request and respond with the appropriate response.

We still have to deal with our new keyword 'notme', so fire up the admin interface and add it as new root keyword. Select the 'notme' keyword and add the following custom content, changing it to your actual site...

<message>
<content>
  Okay, who are you?
 </content>
 <input name="user_name">
  <engine href = "http://www.yoursite.com/dotgo/welcome.engine.php" />
</input>
</message>

Now if our user selects the 'notme' option, they can enter their correct name and then be sent to the welcome engine.

A Note on Sessions

As I mentioned earlier, DOTGO stores the user input with their mobile phone number. If our users are using an emulator over the web, this information will only be stored as long as their browser session is active.

In short, they won't be remembered after they close their browser and will be prompted again for their name the next time they visit. It is not ideal, but we do have to remember that the DOTGO service is based on mobile SMS messaging and the emulator is a workaround for users outside of the supported countries.

Promotional Guidelines

Now that you have all these tools at your disposal and can expand your service, making it truly your own. You are going to want to let the world know you exist. There are some rules and legal requirements that you need to be aware of. The complete guidelines and promotional resources can be found at the DOTGO site.

Just to quickly summarize them here, whenever you promote your dotgo service you must use the mnemonic and numeric designations for dotgo short code channel. You must also provide the mobile disclaimer that text and data rates may apply.

You must notify the user they can opt out or receive help. You must provide a support email, either your own to DOTGO's and link to either your own or DOTGO's privacy policy. A proper promotional statement would look something like this...

Access our services through text messages on your mobile phone.
Text yoursite to DOTCOM (368266)
Message and data rates may apply. Text HELP for help, STOP to opt-out, and email support@dotgo.com for support. View our Privacy Policy.

Conclusion

It has been a journey, however we have finally made it through the introduction to the DOTGO web service. It can get complicated planning all the keyword paths you want available to your users and the PHP dotGo engine package was developed to make this task easier, leaving you to mainly focus on what content to provide instead of how to go about providing it.

This concludes the series of 4 articles on using the PHP dotGo engine and the DOTGO web service. If you would like your own e-book that contains all the instructions in these articles, you can get it from the LeanPub site. It is available for free or if you can afford a small donation, all the author's royalties, my royalties, will be donated to the current cause described on the publications page.

Other than that, if you liked this and the previous articles or you have a question about taking advantage about the DOTGO engine to interact with your users via SMS, post a comment here.


You need to be a registered user or login to post a comment

Login Immediately with your account on:

FacebookGmail
HotmailStackOverflow
GitHubYahoo


Comments:

1. blog comment - kidsnbabies (2016-03-01 08:36)
PHP... - 0 replies
Read the whole comment and replies




  Post a comment Post a comment   See comments See comments (1)   Trackbacks (0)  
  All package blogs All package blogs   PHP dotGo Engine PHP dotGo Engine   Blog PHP dotGo Engine package blog   RSS 1.0 feed RSS 2.0 feed   Blog Better User Interacti...