Skip to content

Instantly share code, notes, and snippets.

@rbocchinfuso
Created August 24, 2018 21:57

Revisions

  1. rbocchinfuso created this gist Aug 24, 2018.
    27 changes: 27 additions & 0 deletions slack-curl-post.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    // post message

    $message = "@$username is working on $text";

    $data = "payload=" . json_encode(array(
    'response_type' => $response_type,
    "text" => $message,
    "icon_emoji" => $icon
    ));

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, SLACK_WEBHOOK);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $result = curl_exec($ch);
    // var_dump($result);
    if($result === false) {
    echo 'Curl error: ' . curl_error($ch);
    }

    curl_close($ch);

    // send ephemeral notification let user know that thier
    echo "@$username you've let everyone on #the-railroad know you are working on $text";