JABTEST2

The JABTEST2 program is set up to show how actions can be triggered when a message is sent from a chat client to the id of the GreenJab listener job running on your IBM i.

For example, you could set up an application to listen for specific commands, even commands from specific IDs, and run a command, program, or return information to the chat client of the requester.

To test the JABTEST2 program, first edit the source for JABTEST2 and change the default value for the fromID:

D fromID          S            256    Inz('youridhere') 

Now compile the program making sure the GREENJAB library is in your library list. This is because this program is set up to use the GREENJAB binding directory in the GREENJAB library.

Next, start a GreenJab listener for the same ID specified in the JABTEST2 program using the GREENJAB command. For my example I used my test asccount, greenjabtest.gmail.com.

Now, start a chat client that has the GreenJab ID in it's list so you can chat with it. Now send a message. The JABTEST2 program should echo back not only the message, but who sent it.

We see in the above example we've already sent one message, and are about to send another.

 H DFTACTGRP(*NO) BNDDIR('GREENJAB')
 ****************************************************************
 *
 * This sample is used to show how you can create a job to run in the background
 *  to wait for messages from any googletalk client to the specified from ID (fromID).
 *
 * When the message is received you can do virtualy anything, so you could have
 *  predefined commands you could send to the listener job using google talk
 *  from any device to run commands, programs, etc.
 *
 * Steps to test:
 * 1. Use the GREENJAB command to start a listener job for the fromID
 * 2. Call this program to start listening for messages
 * 3. Using any device, such as a smartphone, web brower or any chat
 *     client send a message to the fromID specified.
 * 4. This program should echo back the message and the ID that sent the message.
 * 5. Send the message **QUIT** to end the GreenJab listener job.
 *
 ****************************************************************
 * Imports
 ****************************************************************
 /COPY QCOPYSRC,P.GREENJAB
 ****************************************************************
D RC              S             10i 0
D fromID          S            256    Inz('youridhere')
D from            S            256
D message         S          65535
 ********************************************************************
 /free
  // set the from ID, this should be the same ID used in the GREENJAB command
  //  to start the listener job
  #gj_setFromID(fromID);
  dow (#gj_isActive > 0);
    // sit and wait for a message to appear (wait time is -1, which means wait forever)
    if (#gj_deqMsg(from:message:1:-1) > 0);
      // when you recieve a message, echo it back to the server
      RC = #gj_enqMsg(from:'I received the message "' + %trimr(message) +
                         '" from ' + %trimr(from) + '.');
      //we need a way to end the job, so if the user sends QUIT we will send the
      // quit signal to the listener job as well, then end this program.
      if (message = 'QUIT');
        RC = #gj_enqMsg(from:'**QUIT**');
        Leave;
      endif;
    endif;
  enddo;
  *INLR = *ON;
 /end-free