nexylan / slack

MIT License
106 stars 24 forks source link

Nothing shows up on slack, no indication of error (and seemingly no way to check for errors/debug?) #43

Closed HTMLGuyLLC closed 6 years ago

HTMLGuyLLC commented 6 years ago

Tried this way and the same way as your readme (chained with ->from()->to()->send('hi'))

$client = new Client($slack['endpoint'], [
            'username'=>'CRM',
            'channel'=>'#activity'
        ]);

        $msg = $client->createMessage();
        $msg->from($username);
        $msg->to('#'.$channel);
        $msg->withIcon($emoji);
       $client->sendMessage($msg);

I assume something is working because there's no error, but nothing shows up on slack. I'm verified my endpoint twice and can't figure out what's wrong. Any ideas?

Here's what I get when I var_dump the client after sending the message:

object(Nexy\Slack\Client)#2856 (2) {
["options":"Nexy\Slack\Client":private]=> array(8) {
["channel"]=> string(9) "#activity"
["username"]=> string(3) "CRM"
["icon"]=> NULL 
["link_names"]=> bool(false)
["unfurl_links"]=> bool(false)
["unfurl_media"]=> bool(true)
["allow_markdown"]=> bool(true)
["markdown_in_attachments"]=> array(0) { }
}
["httpClient":"Nexy\Slack\Client":private]=> object(Http\Client\Common\HttpMethodsClient)#2866 (2) {
["httpClient":"Http\Client\Common\HttpMethodsClient":private]=> object(Http\Client\Common\PluginClient)#2869 (3) {
["client":"Http\Client\Common\PluginClient":private]=> object(Http\Adapter\Guzzle6\Client)#2874 (1) {
["client":"Http\Adapter\Guzzle6\Client":private]=> object(GuzzleHttp\Client)#2870 (1) {
["config":"GuzzleHttp\Client":private]=> array(7) {
["handler"]=> object(GuzzleHttp\HandlerStack)#2862 (3) {
["handler":"GuzzleHttp\HandlerStack":private]=> object(Closure)#2864 (2) {
["static"]=> array(2) {
["default"]=> object(Closure)#2875 (2) {
["static"]=> array(2) {
["default"]=> object(GuzzleHttp\Handler\CurlMultiHandler)#2873 (5) {
["factory":"GuzzleHttp\Handler\CurlMultiHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#2863 (2) {
["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(0) { }
["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(50) }
["selectTimeout":"GuzzleHttp\Handler\CurlMultiHandler":private]=> int(1)
["active":"GuzzleHttp\Handler\CurlMultiHandler":private]=> NULL 
["handles":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { }
["delays":"GuzzleHttp\Handler\CurlMultiHandler":private]=> array(0) { }
}
["sync"]=> object(GuzzleHttp\Handler\CurlHandler)#2867 (1) {
["factory":"GuzzleHttp\Handler\CurlHandler":private]=> object(GuzzleHttp\Handler\CurlFactory)#2858 (2) {
["handles":"GuzzleHttp\Handler\CurlFactory":private]=> array(0) { }
["maxHandles":"GuzzleHttp\Handler\CurlFactory":private]=> int(3) }
}
}
["parameter"]=> array(2) {
["$request"]=> string(10) ""
["$options"]=> string(10) "" }
}
["streaming"]=> object(GuzzleHttp\Handler\StreamHandler)#2871 (1) {
["lastHeaders":"GuzzleHttp\Handler\StreamHandler":private]=> array(0) { }
}
}
["parameter"]=> array(2) {
["$request"]=> string(10) ""
["$options"]=> string(10) "" }
}
["stack":"GuzzleHttp\HandlerStack":private]=> array(1) {
[0]=> array(2) {
[0]=> object(Closure)#2853 (1) {
["parameter"]=> array(1) {
["$handler"]=> string(10) "" }
} [1]=> string(12) "prepare_body" }
}
["cached":"GuzzleHttp\HandlerStack":private]=> NULL }
["allow_redirects"]=> array(5) {
["max"]=> int(5)
["protocols"]=> array(2) {
[0]=> string(4) "http" [1]=> string(5) "https" }
["strict"]=> bool(false)
["referer"]=> bool(false)
["track_redirects"]=> bool(false) }
["http_errors"]=> bool(true)
["decode_content"]=> bool(true)
["verify"]=> bool(true)
["cookies"]=> bool(false)
["headers"]=> array(1) {
["User-Agent"]=> string(69) "GuzzleHttp/6.3.3 curl/7.47.0 PHP/7.2.8-1+ubuntu16.04.1+deb.sury.org+1" }
}
}
}
["plugins":"Http\Client\Common\PluginClient":private]=> array(1) {
[0]=> object(Http\Client\Common\Plugin\BaseUriPlugin)#2855 (2) {
["addHostPlugin":"Http\Client\Common\Plugin\BaseUriPlugin":private]=> object(Http\Client\Common\Plugin\AddHostPlugin)#2897 (2) {
["host":"Http\Client\Common\Plugin\AddHostPlugin":private]=> object(GuzzleHttp\Psr7\Uri)#2898 (7) {
["scheme":"GuzzleHttp\Psr7\Uri":private]=> string(5) "https"
["userInfo":"GuzzleHttp\Psr7\Uri":private]=> string(0) ""
["host":"GuzzleHttp\Psr7\Uri":private]=> string(15) "hooks.slack.com"
["port":"GuzzleHttp\Psr7\Uri":private]=> NULL 
["path":"GuzzleHttp\Psr7\Uri":private]=> string(54) "/services/{{____INFO_HERE_IS_PROBABLY_A_SECURITY_CONCERN_SO_IM_HIDING____}}"
["query":"GuzzleHttp\Psr7\Uri":private]=> string(0) ""
["fragment":"GuzzleHttp\Psr7\Uri":private]=> string(0) "" }
["replace":"Http\Client\Common\Plugin\AddHostPlugin":private]=> bool(false) }
["addPathPlugin":"Http\Client\Common\Plugin\BaseUriPlugin":private]=> object(Http\Client\Common\Plugin\AddPathPlugin)#2896 (1) {
["uri":"Http\Client\Common\Plugin\AddPathPlugin":private]=> object(GuzzleHttp\Psr7\Uri)#2898 (7) {
["scheme":"GuzzleHttp\Psr7\Uri":private]=> string(5) "https"
["userInfo":"GuzzleHttp\Psr7\Uri":private]=> string(0) ""
["host":"GuzzleHttp\Psr7\Uri":private]=> string(15) "hooks.slack.com"
["port":"GuzzleHttp\Psr7\Uri":private]=> NULL 
["path":"GuzzleHttp\Psr7\Uri":private]=> string(54) "/services/{{____INFO_HERE_IS_PROBABLY_A_SECURITY_CONCERN_SO_IM_HIDING____}}"
["query":"GuzzleHttp\Psr7\Uri":private]=> string(0) ""
["fragment":"GuzzleHttp\Psr7\Uri":private]=> string(0) "" }
}
}
}
["options":"Http\Client\Common\PluginClient":private]=> array(2) {
["max_restarts"]=> int(10)
["debug_plugins"]=> array(0) { }
}
}
["requestFactory":"Http\Client\Common\HttpMethodsClient":private]=> object(Http\Message\MessageFactory\GuzzleMessageFactory)#2889 (0) { }
}
}
HTMLGuyLLC commented 6 years ago

I suggest you return the http client when you send the message or create a public method to get last http code.

HTMLGuyLLC commented 6 years ago

I was looking for it in the wrong channel and I had the other channel muted! ha. Wow.

HTMLGuyLLC commented 6 years ago

On the plus side, I realized how ridic it is to use your package anyway.

It's literally less code to post directly to slack, and I've already got this code inside a symfony service I created a while ago that used a diff package that wasn't symfony 4 compatible.

$client = new Client();

        return $client->post($this->endpoint, [
            RequestOptions::JSON =>[
                'text'=>$this->env.':'.$msg,
                'icon_emoji'=>$emoji,
                'username'=>$username,
                'channel'=>'#'.$channel
            ]
        ]);