Pages Menu
TwitterRssFacebook

Posted by on Apr 17, 2012 in Everything Else, Skype for Business® (Lync®)

UCMA 4 – The Numbers Game Example

UCMA 4 – The Numbers Game Example

This is the final post in a series of 4 on using UCMA Workflow (series starts here). If you need more information on this or are looking for a reference guide, I highly recommend Professional Unified Communications by George Durzi & Michael Greenlee, which has an entire chapter (50 pages) devoted to Workflow.

By now you should be fairly happy with the concept of using the UCMA Worfklow SDK to create visual representations of UCMA applications. From the last post you saw how easy it was to create a simple IVR application to route calls to the appropriate department based on user feedback.

In this post I want to show you a different example. It’s got no real use, but it does highlight the many varied things you can do with the workflow. It also demonstrates an important point, which is that you can manipulate the graphic workflow you see at design time in code at run-time, modifying properties and values to fit your needs. It’s an implementation of (what I call) the Numbers Game.

The Numbers Game

The numbers game is a simple programming example. The application “thinks” of a number and the user has to guess what that number is. The only permissible feedback the application can give is whether the selected number is too low, too high, or correct.

It’s similar in a way (though not the same) as the game played in Play Your Cards Right – a classic British TV show from the 1980’s, brought back to life briefly in the late 1990’s and apparently being re-flogged back into existence later this year.  I think it’s just the audience shouting of “Higher”, “Lower” that reminds me of it, though I need no further prompting to show you this piece of classic Bruce Forsyth from 1980. (In true Brucie style, the actual game isn’t until the 9 min mark (total length 9min 58sec) the remainder being one-liners, bad jokes and innuendo):


Anyway, I wanted to create a UCMA Workflow application which demonstrated that you could perform workflow rules and this seemed to fit the bill.

If you have read my previous post in the series, you’ll know I went through an extended walkthrough of exactly how to author an IVR application. Therefore, I’m not going to do that this time: instead I’ll show you the workflow graphic, and point out at a high-level anything not obvious:

A couple of explanatory points:

  • the produceRandomNumber shape and the others that look like it are codeShapes. You can add these anywhere in your workflow and then execute custom-written code when they are hit. I’m using this to create a random number and store it in a class-wide field so it can be checked later against the user’s choice of number.
  • with the workflow I’ve set the MainPrompt for the speechQuestionAnswer shape to be something like I’m thinking of a number between 1 and 50, what is it?. I’ve also pre-populated the ExpectedSpeechInputs with discrete values between 1 and 50, though you could easily (and probably preferably) do this in code.
  • Once the user had said one of the expected speech inputs I check to see whether the value is a valid integer. This shouldn’t be nessecary because in theory the speechQuestionAnswer shape will only allow valid values, which are all valid integers. However, I need to perform mathmatical integer operations on them (greater than, less than, equal to) so I want to be sure they are OK. I do this with some custom code, using Integer.TryParse. If the value isn’t valid a GoTo shape sends control back to the question.
  • Assuming a valid response, the user’s response is checked against the stored random number in the two left hand If-Else branches, one for GreaterThan and the other for LessThan.  In each case, custom code then resets the MainPrompt of the speechQuestionAnswer shape, then redirects the user back the question. This is a nice way of ensuring that the game flow stays quick and engaging, as the “question” changes to “Higher!” or “Lower!” each time. (An important and obvious point here is that if you redirect back to a speechQuestionAnswer shape, be prepared to have the question read out again:
  • There’s no condition set on the far right branch. If neither of the first two branches are true, then the user’s number must be the same as the random number, and the user has “won”. A short speechStatement shape prompt congratulates them and sends them on their way to pick up the giant teddy (or whatever it was they used to win on Play Your Cards Right).

I encourage you to code up this example on your own infrastructure. It won’t take a moment, will be good fun and is an good example of what can be done with UCMA. Who knows, maybe in the future all on-hold services will offer this level of interactive waiting?!

Written by Tom Morgan

Tom is a Microsoft Teams Platform developer and Microsoft MVP who has been blogging for over a decade. Find out more.
Buy the book: Building and Developing Apps & Bots for Microsoft Teams. Now available to purchase online with free updates.

2 Comments

  1. Hi Diego – you’re right in what you read, UCMA Workflow isn’t supported in UCMA 4, only in UCMA 3. Sorry for the confusion : the blog post title is because the post is number 4 in a series of posts all about using UCMA Workflow, which I wrote back in 2012 using UCMA 3.0.

    -tom

Trackbacks/Pingbacks

  1. UCMA Workflow 3 – IVR Example | Developing Lync - [...] way that promotes solution thinking with regard to workflow-orientated problems such as IVR. In the next post I’ll show…

Post a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.