Quick Start Example

From Developer Wiki

Once you have enabled Mozes API access on your Mozes account, here are the 3 steps to take to get things working

1. Code it!

Write a program to take action when called from Mozes, and to return XML data conforming to Mozes’ specifications. This example allows users to vote on a yes/no question by texting "samplevote y" or "samplevote n". The keyword owner can announce to a group the question and the instructions for responding. The users receive a running vote count on their phone and Mozes account. Here is the content of votescript.cgi:

#!/usr/bin/perl
use CGI;
my $query = new CGI;
my $result = "Please vote \"samplevote yes\"" .
 ", \"samplevote no\", or " .
 "\"samplevote tally\" to just see the results.";
my $vote = lc($query->param("vote"));
if ($vote eq "y") {
 $vote = "yes";
} elsif ($vote eq "n") {
 $vote = "no";
} elsif ($vote eq "t") {
 $vote = "tally";
}
if (($vote eq "yes") || ($vote eq "no") ||
  ($vote eq "tally")) {
 my $yes = 0;
 my $no = 0;
 my $filename = "/var/www/data/vote.txt";
 if (-e $filename) {
  open(RD,$filename);
  my $line = <RD>;
  $line =~ s/\D//gs;
  $yes = $line;
  $line = <RD>;
  $line =~ s/\D//gs;
  $no = $line;
  close(RD);
}
if (($vote eq "yes") || ($vote eq "no")) {
 if ($vote eq "yes") {
  $yes++;
 } else {
  $no++;
 }
 open(WR,">" . $filename);
 print WR $yes . "\n" . $no . "\n";
 close(WR);
}
$result = "Received a " . $vote .
 ". As of your texting, the total is " .
 $yes . " yes and " . $no . " no.";
}
print "Content-Type: text/xml\r\n\r\n" .
 "<?xml version=\"1.0\" " .
 "encoding=\"ISO-8859-1\" ?>\n" .
 "<MozesDynamicContent>\n" .
 "<Result>" . $result . "</Result>\n" .
 "</MozesDynamicContent>\n"; 

2. Call it!

In the API tab in the keyword definition, specify the URL call to your program with parameters.

When editing the "samplevote" keyword, enter in Dynamic Content URL (click the "Click here" link to expose the text box for the URL if necessary):

http://my.server.com/cgi-bin/votescript.cgi?vote=<parameter>

3. Place it!

Specify where in the keyword the returned data (if any) should be placed.

While editing the keyword "samplevote", go to the Actions tab and for the text message enter:

<DynamicResult>

Or, to use it as a fill-in-the-blank, enter something like:

 Your result was <DynamicResult>.