<?php

ini_set('default_socket_timeout', 600);
try {
    $client = new SoapClient("https://process-centric-services.herokuapp.com/processCentricServices?wsdl", array("connection_timeout" => 360));
    $channel = "#tests";
    $trigger_word = $_REQUEST['trigger_word'];
    $trigger_word = strtolower($trigger_word);
    $slack_user_id = $_REQUEST['user_id'];
    $user_name = $_REQUEST['user_name'];
    if ($trigger_word == "register") {
        $inWebhookUrl = "https://hooks.slack.com/services/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";
        $params = array("slack_user_id" => $slack_user_id, "user_name" => $user_name);
        $response = $client->initializeUser($params);
        $message = "";
        $attachment = "";
        if ($response->id == -1) {
            $message = "Bad parameters";
        } else {
            if ($response->id == -2) {
                $message = "Error in some called server!";
            } else {
                if ($response->id == -3) {
                    $message = "No error, but got bad response!";
                } else {
                    if ($response->id == -4) {
                        $message = "You are already registered! Here is what you can do:";
                        $attachment = array(['color' => '#5AAC56', 'fields' => array(array('title' => 'setgoal [goal_type] [target_value] [period]', 'value' => 'Set a fitness goal', 'short' => false), array('title' => 'run [distance] [time] [calories]', 'value' => 'Add a new run', 'short' => false), array('title' => 'goalstatus', 'value' => 'Check where you stand', 'short' => false))]);
                    } else {
                        if ($response->id > 0) {
                            $message = "You have been registered! Here is what you can do: ";