public function sendWebHook($message)
    {
        $url = $this->config->getIncomingWebhookURL();
        $messagePrefix = $this->config->getWebhookMessagePrefix();
        $currentUsername = 'System';
        try {
            if ($this->state->getAreaCode() == 'adminhtml') {
                $getUser = $this->authSession->getUser();
                if (!empty($getUser)) {
                    $currentUsername = $getUser->getUserName();
                }
            }
        } catch (\Exception $e) {
            $this->log->log(100, 'Failed to retrieve Area Code');
        }

        $storeName = $this->helper->getStoreName();
        $storeUrl = $this->helper->getStoreUrl();

        $text =  $messagePrefix.' user='.$currentUsername.' '.$message.' on <'.$storeUrl.'|Store> | '.$storeName;

        $headers = [
            'Content-type: application/json'
        ];

        $body = json_encode([
            "text"  =>  $text,
            "username" => "fastly-magento-bot",
            "icon_emoji"=> ":airplane:"
        ]);

        $client = $this->curlFactory->create();
        $client->addOption(CURLOPT_CONNECTTIMEOUT, 2);
        $client->addOption(CURLOPT_TIMEOUT, 3);
        $client->write(\Zend_Http_Client::POST, $url, '1.1', $headers, $body);
        $response = $client->read();
        $responseCode = \Zend_Http_Response::extractCode($response);

        if ($responseCode != 200) {
            $this->log->log(100, 'Failed to send message to the following Webhook: '.$url);
        }

        $client->close();
    }
public function sendWebHook($message)
    {
        $url = $this->config->getIncomingWebhookURL();
        $messagePrefix = $this->config->getWebhookMessagePrefix();
        $currentUsername = 'System';
        try {
            if ($this->state->getAreaCode() == 'adminhtml') {
                $getUser = $this->authSession->getUser();
                if (!empty($getUser)) {
                    $currentUsername = $getUser->getUserName();
                }
            }
        } catch (\Exception $e) {
            $this->log->log(100, 'Failed to retrieve Area Code');
        }

        $storeName = $this->helper->getStoreName();
        $storeUrl = $this->helper->getStoreUrl();

        $text =  $messagePrefix.' user='.$currentUsername.' '.$message.' on <'.$storeUrl.'|Store> | '.$storeName;

        $headers = [
            'Content-type: application/json'
        ];

        $body = json_encode([
            "text"  =>  $text,
            "username" => "fastly-magento-bot",
            "icon_emoji"=> ":airplane:"
        ]);

        $client = $this->curlFactory->create();
        $client->addOption(CURLOPT_CONNECTTIMEOUT, 2);
        $client->addOption(CURLOPT_TIMEOUT, 3);
        $client->write(\Zend_Http_Client::POST, $url, '1.1', $headers, $body);
        $response = $client->read();
        $responseCode = \Zend_Http_Response::extractCode($response);

        if ($responseCode != 200) {
            $this->log->log(100, 'Failed to send message to the following Webhook: '.$url);
        }

        $client->close();
    }
public function sendWebHook ( $ message ) { $ url = $ this -> config -> getIncomingWebhookURL ( ) ; $ messagePrefix = $ this -> config -> getWebhookMessagePrefix ( ) ; $ currentUsername = 'System' ; try { if ( $ this -> state -> getAreaCode ( ) == 'adminhtml' ) { $ getUser = $ this -> authSession -> getUser ( ) ; if ( ! empty ( $ getUser ) ) { $ currentUsername = $ getUser -> getUserName ( ) ; } } } catch ( \ Exception $ e ) { $ this -> log -> log ( 100 , 'Failed to retrieve Area Code' ) ; } $ storeName = $ this -> helper -> getStoreName ( ) ; $ storeUrl = $ this -> helper -> getStoreUrl ( ) ; $ text = $ messagePrefix . ' user=' . $ currentUsername . ' ' . $ message . ' on <' . $ storeUrl . '|Store> | ' . $ storeName ; $ headers = [ 'Content-type: application/json' ] ; $ body = json_encode ( [ "text" => $ text , "username" => "fastly-magento-bot" , "icon_emoji" => ":airplane:" ] ) ; $ client = $ this -> curlFactory -> create ( ) ; $ client -> addOption ( CURLOPT_CONNECTTIMEOUT , 2 ) ; $ client -> addOption ( CURLOPT_TIMEOUT , 3 ) ; $ client -> write ( \ Zend_Http_Client :: POST , $ url , '1.1' , $ headers , $ body ) ; $ response = $ client -> read ( ) ; $ responseCode = \ Zend_Http_Response :: extractCode ( $ response ) ; if ( $ responseCode != 200 ) { $ this -> log -> log ( 100 , 'Failed to send message to the following Webhook: ' . $ url ) ; } $ client -> close ( ) ; }
Send message to Slack channel

@param $message
Send message to Slack channel