Creating Interactive Applications


Once you have the basics of an application, you will want to allow users to have conversations with the gateway itself. While these conversations may not resemble that of a normal human user, they can be programmed to provide a very high level of access to information over a small connection if the application is able to recognize a few simple commands.

In the case of our application it would be great if helpdesk staff could IM in and mark a task as complete and request the next task to be assigned to them. We can create a limited vocabulary of words that the gateway will understand and share this with our users then we can get the application to communicate to our helpdesk operatives quite easily.

TIP

You might want to build a simple form that calls your onIncomingEvent method directly as apposed to using an IM client to test your application. That way you will get the debug output when things go wrong.


We have opted for a very small selection of words that our gateway will understand. It will understand Accept, Assign, Reject, Deny, Complete, Close and Details. For many of the functions, we have also allowed the user to just enter the first letter of the command and we will understand it.

When building the request/response logic you will want to make sure that any and all of the backend data gathering code elsewhere, in this example we told our gateway CFC to extend another CFC, our helpdesk CFC so it would have access to all of the underlying database access code. In our application they provide access to the issues database.

Listing 32.5. im.cfcInteractive IM Gateway CFC

[View full width]

 <cfcomponent extends="helpdesk"> <cffunction name="onIncomingMessage">   <cfargument name="CFEvent" type="struct" required="YES">   <!--- Generate and return the message.--->   <cfset message = trim(arguments.CFEvent.data.MESSAGE)>   <cfset keyword = listFirst(message," ")>   <cfset msg = "">   <cfscript>     switch (keyword) {     case "accept":           staffDetails = getStaffDetails(imid=arguments.CFEvent.data.SENDER);           taskID = assignTask(staffDetails.userid);           msg = staffDetails.name & " thankyou for accepting this task.                 The task ID is " & taskID;           break;     case "A":     case "Assign":           staffDetails =getStaffDetails(imid=arguments.CFEvent.data.SENDER);           taskID = assignTask(staffDetails.userid);           if(len(taskID) eq 0) {             msg = "there are no unassigned tasks at this time";           } else {             msg = "You have been assigned a new task.";           }           break;     case "R":     case "reject":     case "deny":           msg = "This task has been rejected, it will be returned to the queue."                 & chr(13);;           msg = msg & "You can always mark yourself as 'Away' and the helpdesk                 system will not automaticly alert you to new tasks";           break;     case "C":     case "Complete":     case "Close":           // go and work out who this user is and go and get their current list of            tasks           staffDetails =getStaffDetails(imid=arguments.CFEvent.data.SENDER);           aDetails = getTaskDetails(staffDetails.userid);           switch(arrayLen(aDetails)) {           case 0:                msg = "You do not have any tasks currently active" & chr(13);                break;           case 1:                closeIssue(aDetails[1].id);                msg = "You have marked your currently active task as complete."                      & aDetails[1].id& chr(13);                break;           default:                // this user has more than one case                //check for a number after the keyword if present,                //close that case                if(listLen(message,' ') gt 1                   and isNumeric(ListGetAt(message,2,' '))) {                  thisTask =ListGetAt(message,2,' ');                  closeIssue(aDetails[thisTask].id);                  msg = "You have closed task " & thisTask & ".";                } else {                  msg = "You have more than one task open at present.                         Please confirm which task you wish to close." & chr(13);                  for(i =1;i lte arrayLen(aDetails);i=i+1) {                    msg = msg & i & ". " & aDetails[i].Subject & chr(13);                  }                }            }            break;     case "D":     case "Details":          staffDetails =getStaffDetails(imid=arguments.CFEvent.data.SENDER);          aDetails = getTaskDetails(staffDetails.userid);          if(listLen(message,' ') gt 1 and             isNumeric(ListGetAt(message,2,' '))) {            // this user has asked for a task            thisTask = ListGetAt(message,2,' ');            msg = "Details for task " & thisTask &chr(13);            msg = msg & "Subject: " & aDetails[thisTask].Subject & chr(13);            msg = msg & aDetails[thisTask].body & chr(13);            msg = msg & "Requested by: " & aDetails[thisTask].loggedby & chr(13);          } else {            // work out how many cases this user has and send details            switch (arrayLen(aDetails)) {            case 0:                 msg = "You currently have no cases assigned to you.                        Do you wish to be assigned a new support case?                        (Assign?)";                 break;            case 1:                 msg = "Subject: " & aDetails[1].Subject & chr(13);                 msg = msg & aDetails[1].body & chr(13);                 msg = msg & "Requested by: " & aDetails[1].loggedby & chr(13);                 break;            default:                 msg = "You have " & arrayLen(aDetails)                       & " currently assigned to you." & chr(13);                 msg = msg & "To have the details of one issue use                       the command 'D xx' where xx is the number infront                       of the subject" & chr(13);                       for(i =1;i lte arrayLen(aDetails);i=i+1) {                         msg = msg & i & ". " & aDetails[i].Subject & chr(13);              }            }          }          break;     default:          if(len(keyword) neq 0) msg = "Your keyword '" &             keyword & "' was not recoginsed." & chr(13) & chr(13);          msg = msg & "Help" & chr(13);          msg = msg & "The following keywords are accepted by this system" & chr(13);          msg = msg & "Details - lists the details of your                       current task. You can append a task id to this                       command if you want the details of a single task." & chr(13);          msg = msg & "Help - Displays this page" & chr(13);     } </cfscript>   <!--- return the message --->   <cfscript>     retrunVal = structNew();     retrunVal.command = "submit";     retrunVal.buddyID = arguments.CFEvent.data.SENDER;     retrunVal.message = msg;     return retrunVal;   </cfscript> </cffunction> </cfcomponent> 

As you can see, there is a lot of code that goes into working out what the user actually wants and this is not the most intelligent system out there. If you want to see just how smart an automated IM system (often called an IM Robot or 'bot for short) is, using your AOL chat client, chat to ZolaOnAol. She is a completely code driven IM interface, only in Java not ColdFusion.

For more details visit http://aimtoday.aol.com/features/main_redesign.adp?fid=zola.




Advanced Macromedia ColdFusion MX 7 Application Development
Advanced Macromedia ColdFusion MX 7 Application Development
ISBN: 0321292693
EAN: 2147483647
Year: 2006
Pages: 240
Authors: Ben Forta, et al

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net