コード例 #1
0
function dicebot($info)
{
    $obj = arr2obj($info);
    /* username to send reply to */
    $to_username = $obj->notifo_from_username;
    /* compute response here */
    $msg = strtolower($obj->notifo_message);
    $arr = explode(" ", $msg);
    $commands_arr = array("flip", "help", "hi", "hello");
    $command = strtolower($arr[0]);
    if (!in_array($command, $commands_arr)) {
        /* invalid command, tell them to send help for info */
        $message = "Send the command 'help' for more info.";
    } else {
        if ($command == "flip") {
            $coins = array("Heads", "Tails");
            $flip = mt_rand(0, 99);
            if ($flip < 50) {
                $flip = 0;
            } else {
                $flip = 1;
            }
            $message = "You flipped a coin: " . $coins[$flip] . ".";
        } else {
            /* sent help, hi, or hello */
            $message = "Hello, send the command 'flip' to flip a coin!";
        }
    }
    $notifo = new Notifo_API(NOTIFO_SERVICE_USERNAME, NOTIFO_APISECRET);
    $notifo->send_message(array("to" => $to_username, "msg" => $message));
}
コード例 #2
0
ファイル: Notifo.php プロジェクト: rasismeiro/cintient
 public function fire($msg, $params = array())
 {
     if ($this->isEmpty()) {
         return false;
     }
     include_once 'lib/Notifo_API.php';
     $notifo = new Notifo_API($this->getUsername(), $this->getKey());
     $payload = array('label' => 'Cintient', 'msg' => $msg);
     if (!empty($params['uri'])) {
         $payload['uri'] = $params['uri'];
     }
     if (!empty($params['title'])) {
         $payload['title'] = $params['title'];
     }
     $response = $notifo->send_notification($payload);
     // If notifo.com is unreachable (happened before), response is null
     if (is_null($response) || empty($response)) {
         // TODO: Persist these notifications for later retry? Or for
         // showing them to the user on the web page?
         SystemEvent::raise(SystemEvent::INFO, "Notifo seems to be unreachable. [TITLE={$params['title']}] [MSG={$msg}]", __METHOD__);
         return false;
     }
     $response = json_decode($response, true);
     //
     // Check out: https://api.notifo.com/docs/responses
     //
     if (!empty($response['response_code']) && $response['response_code'] == '2201') {
         return true;
     } else {
         SystemEvent::raise(SystemEvent::INFO, "Notifo notification returned error. [RSP_CODE={$response['response_code']}] [RSP_MSG={$response['response_message']}]", __METHOD__);
         return false;
     }
 }
コード例 #3
0
<?php

/* include the Notifo_API PHP library */
include "Notifo_API.php";
/* create a new "notifo" object */
$notifo = new Notifo_API("username", "apisecret");
/* set the notification parameters */
$params = array("to" => "username", "label" => "Dictionary", "title" => "Word of the Day", "msg" => "chuffed: delighted; pleased; satisfied.", "uri" => "http://dictionary.com");
/* send the notification! */
$response = $notifo->send_notification($params);
/* handle response below */
/* ... */