Title: WLA: Detect if user can't launch an Activity
Slug: wla-detect-if-user-can-t-launch-an-activity
Date: 2007-10-02 12:26:00
Author: Kartones
Lang: en
Tags: Development, Troubleshooting, Windows Live Agents
Description: A guide on detecting and handling issues when a user can't launch an activity in MSN Messenger.

<p>Today I'm gonna talk about MSN Messenger Activities stuff. Using activities from Buddyscript means adding handlers in the form of overriden procedures, creating a mini-communication framework (the SDK contains a good example to start from), plus all the code we want to add to make our code more robust and handle possible errors. <br>I'll focus on detecting and handling problems when for whatever reason the user can't launch an activity.</p> <p align="justify">To use the following code, you must reference <font face="Courier New">lib:/Shared/Utilities/WLMActivityUtilities.pkg</font>, don't forget to ;)</p> <p align="justify">First of all, we can detect if the activity is already launched or not. To do this, BuddyScript has the <font face="Courier New">MSNSLPP4ApplicationIsAvailable()</font> function. I always have additional flags to reflect the action I want the activity to perform when is ready, the state in which it is,... so it's a good idea to wrap this function in another one containing your custom checks too.</p> <p align="justify">If, for some reason the user can't launch the activity, the <font face="Courier New">MSNSLPUserCanNotOpenP4Window()</font> procedure will be called, so you must place an override too in your code, reseting all flags and handling this "disaster".</p> <p align="justify">If the user refuses explicitly to launch the activity, the raised procedure is <font face="Courier New">MSNSLPUserRejectedInvitationToOpenP4Window()</font>.</p> <p align="justify">The main call to launch the activity is <font face="Courier New">MSNSLPSendInvitationToOpenP4Application("activityID", "activityName")</font>, but it is a good practice to wrap it in another procedure to check first if user can't launch it, and to avoid having to write the ID and name of the desired activity.</p> <p align="justify">And finally we get into the interesting things. What if the client is running a Web Messenger? Or Messenger from a PDA? Or an old version which can't handle Activities?</p> <p align="justify">With the following code, you can detect all that, and by checking it before launching the activity, avoid most problems and redirect to the "user doesn't supports activities" code fork:</p> <p><font face="Courier New"><font color="#008040">// Checks if the client is on a mobile device, on Web Messenger, or has an old msgr version</font><br>function ClientSupportsActivities()<br>  if !Exist(SYS.History[0].Query.ExtraInfo.ClientId)<br>    return false<br>  CLIENTID = SYS.History[0].Query.ExtraInfo.ClientId<br>  if (CLIENTID &amp; 512) != 0 || (CLIENTID &amp; 1) != 0 || (CLIENTID &amp; 4026531840) &lt; 1073741824<br>    return false<br>  else<br>    return true</font></p>
