-user_id -type_id system -device_id 4 -payload '{"timetrex":{"event":[{"type":"open_view","action":"edit","view_name":"InOut","data":{"type_id":30,"status_id":20}}]}}' // **Send notification that opens MyAccount -> Request, Add. No notification is saved.** // Payload: {"timetrex":{"event":[{"type":"open_view","action":"edit","view_name":"Contact Information","data":{}}]}} // Type: open_view // View_name: Request // Action: add // edit, add, view // Data: {} // Full Command: send_push_notification.php -api_key -user_id -type_id system -device_id 4 -payload '{"timetrex":{"event":[{"type":"open_view","action":"add","view_name":"Request","data":{"type_id":30}}]}}' // **Send notification that opens MyAccount -> Contact Information. No notification is saved.** // Payload: {"timetrex":{"event":[{"type":"open_view","action":"edit","view_name":"Contact Information","data":{}}]}} // Type: open_view // View_name: Contact Information // Action: edit // edit, add, view // Data: {} // Full Command: send_push_notification.php -api_key -user_id -type_id system -device_id 4 -payload '{"timetrex":{"event":[{"type":"open_view","action":"edit","view_name":"Contact Information","data":{}}]}}' // **Send notification that redirects to a URL** // Payload: {"timetrex":{"event":[{"ask":1,"text":"Sending you to google.","link":"https://www.google.com/"}]}} // Ask: 1 // 0=dont ask, 1=ask (If user receives a prompt) // Text: Sending you to google. //Any text if user is getting an ask prompt. // Link: https://www.google.com/ // Full Command: send_push_notification.php -api_key -user_id -type_id system -device_id 4 -payload '{"timetrex":{"event":[{"type":"redirect","ask":1,"text":"Sending you to google.","link":"https://www.google.com/"}]}}' // **Send a system notification with a title/body for "System going down for maintenance at 4PM".** // No payload required. // Full Command: send_push_notification.php -api_key -user_id -type_id system -device_id 4 -title_short 'System Maintenance' -body_short 'System going down for maintenance at 4PM' // send_push_notification.php -api_key -user_id -type_id system -device_id 4 -payload "" if ( $argc < 2 || in_array( $argv[1], [ '--help', '-help', '-h', '-?' ] ) ) { $help_output = "Usage: send_push_notification.php [OPTIONS]\n"; $help_output .= "\n"; $help_output .= " Options:\n"; $help_output .= " -server URL to API server\n"; $help_output .= " -username API username\n"; $help_output .= " -password API password\n"; $help_output .= " -api_key API key to use instead of username/password\n"; $help_output .= " -user_id Destination Employee\n"; $help_output .= " -type_id Type (ie: system)\n"; $help_output .= " -object_type_id Object Type ID (ie: 0=System)\n"; $help_output .= " -object_id Object ID\n"; $help_output .= " -title_short Title (Short)\n"; $help_output .= " -title_long <title> Title (Long)\n"; $help_output .= " -body_short <body> Body (Short)\n"; $help_output .= " -body_long <body> Body (Long)\n"; $help_output .= " -priority <priority> Priority (ie: 1=Critical, 2=High, 5=Normal, 10=Low)\n"; $help_output .= " -device_id <device_id> Devices (ie: 4=Web Browser, 256=Work Email, 512=Home Email, 32768=App)\n"; $help_output .= " -payload <payload> (Optional) Raw Payload in JSON format\n"; echo $help_output; } else { //Handle command line arguments $last_arg = count( $argv ) - 1; if ( in_array( '-server', $argv ) ) { $api_url = trim( $argv[( array_search( '-server', $argv ) + 1 )] ); } else { $api_url = false; } if ( in_array( '-username', $argv ) ) { $username = trim( $argv[( array_search( '-username', $argv ) + 1 )] ); } else { $username = false; } if ( in_array( '-password', $argv ) ) { $password = trim( $argv[( array_search( '-password', $argv ) + 1 )] ); } else { $password = false; } if ( in_array( '-api_key', $argv ) ) { $api_key = trim( $argv[array_search( '-api_key', $argv ) + 1] ); } else { $api_key = false; } if ( in_array( '-user_id', $argv ) ) { $user_id = trim( $argv[array_search( '-user_id', $argv ) + 1] ); } else { $user_id = false; } if ( in_array( '-type_id', $argv ) ) { $type_id = trim( $argv[array_search( '-type_id', $argv ) + 1] ); } else { $type_id = 'system'; } if ( in_array( '-object_type_id', $argv ) ) { $object_type_id = trim( $argv[array_search( '-object_type_id', $argv ) + 1] ); } else { $object_type_id = false; } if ( in_array( '-object_id', $argv ) ) { $object_id = trim( $argv[array_search( '-object_id', $argv ) + 1] ); } else { $object_id = false; } if ( in_array( '-title_short', $argv ) ) { $title_short = trim( $argv[array_search( '-title_short', $argv ) + 1] ); } else { $title_short = false; } if ( in_array( '-title_long', $argv ) ) { $title_long = trim( $argv[array_search( '-title_long', $argv ) + 1] ); } else { $title_long = false; } if ( in_array( '-body_short', $argv ) ) { $body_short = trim( $argv[array_search( '-body_short', $argv ) + 1] ); } else { $body_short = false; } if ( in_array( '-body_long', $argv ) ) { $body_long = trim( $argv[array_search( '-body_long', $argv ) + 1] ); } else { $body_long = false; } if ( in_array( '-priority', $argv ) ) { $priority = trim( $argv[array_search( '-priority', $argv ) + 1] ); } else { $priority = 5; //5=Normal } if ( in_array( '-device_id', $argv ) ) { $device_id = [ trim( $argv[array_search( '-device_id', $argv ) + 1] ) ]; } else { $device_id = [ 4 ]; //Default to Web Browser, Work Email, and Mobile App. } if ( in_array( '-payload', $argv ) ) { $raw_payload = json_decode( trim( $argv[array_search( '-payload', $argv ) + 1] ), true ); $raw_payload_json_error = json_last_error(); if ( $raw_payload_json_error !== JSON_ERROR_NONE ) { echo 'ERROR: Invalid JSON: '; switch ( $raw_payload_json_error ) { case JSON_ERROR_NONE: echo 'No errors'; break; case JSON_ERROR_DEPTH: echo 'Maximum stack depth exceeded'; break; case JSON_ERROR_STATE_MISMATCH: echo 'Underflow or the modes mismatch'; break; case JSON_ERROR_CTRL_CHAR: echo 'Unexpected control character found'; break; case JSON_ERROR_SYNTAX: echo 'Syntax error, malformed JSON'; break; case JSON_ERROR_UTF8: echo 'Malformed UTF-8 characters, possibly incorrectly encoded'; break; default: echo 'Unknown error'; break; } echo "\n"; exit( 254 ); } } else { $raw_payload = null; } $TIMETREX_URL = $api_url; if ( isset( $api_key ) && $api_key != '' ) { $TIMETREX_SESSION_ID = $api_key; $api_session = new TimeTrexClientAPI(); //if ( $api_session->isLoggedIn() == false ) { // echo "API Key is incorrect!\n"; // exit( 1 ); //} } else { $api_session = new TimeTrexClientAPI(); $api_session->Login( $username, $password ); if ( $TIMETREX_SESSION_ID == false ) { echo "API Username/Password is incorrect!\nIf multifactor authentication is enabled, login to TimeTrex and go to Profile -> Security / Passwords, More (...) -> Register API Key.\n"; exit( 1 ); } //echo "Session ID: $TIMETREX_SESSION_ID\n"; } $notification_data = [ 'user_id' => $user_id, 'device_id' => $device_id, 'type_id' => $type_id, 'object_type_id' => $object_type_id, 'object_id' => $object_id, 'title_short' => $title_short, 'title_long' => $title_long, 'body_short' => $body_short, 'body_long' => $body_long, 'priority_id' => $priority, 'payload' => $raw_payload, ]; $notification_obj = new TimeTrexClientAPI( 'Notification' ); $notification_obj->setIdempotentKey( false ); //Turn off idempotenacy. $notification_result = $notification_obj->sendNotification( $notification_data ); $retval = $notification_result->getResult(); if ( $retval !== true ) { echo "ERROR: Unable to send notification!\n"; exit ( 1 ); } } //Debug::Display(); Debug::writeToLog(); ?>