DanMossa
DanMossa

Reputation: 1092

Slack bot API no longer works

I have a slackbot that posts a message for a user and was working for a few months without any hiccups but is now not posting a message, after some digging I see that the error I'm getting back from slack is

{
   "ok":false,
   "error":"invalid_request_data"
}

Googling hasn't helped me find anything and I'm not sure what the problem is now knowing that it was working this whole time and no code has changed.

When the user types in a slash command, it hits a php file interactive.php this allows the user to fill out some information and that information then gets sent to deploy.php via slack as well

This is the deploy.php file

<?php
$receivedRequest = json_decode($_POST['payload'], true);

$type = $receivedRequest["type"];

if ($type != "dialog_submission") {
    exit("No");
}

$response_url = $receivedRequest["response_url"];
$user_id = $receivedRequest["user"]["id"];
$service = $receivedRequest["submission"]["service"];
$rollback = $receivedRequest["submission"]["rollback"];
$target = $receivedRequest["submission"]["target"];
$featureList = $receivedRequest["submission"]["featureList"];
$diff = $receivedRequest["submission"]["diff"];
$environment = $receivedRequest["submission"]["environment"];
$canary = $receivedRequest["submission"]["canary"];

if ($canary == "yes"){
    $environment = $environment . " _canary_ ";
}

$data = [
    "response_type" => "in_channel",
    "text" =>
        "<@" . $user_id . ">" . " is deploying *" . $service . "* to *" . $environment . "*" .
        "\n" .
        "*rollback: " . $rollback . " target: " . $target . "*\n" .
        $featureList . "\n" .
        "Diff: " . $diff . "\n <!here>"
];

$payload = json_encode($data);

// Prepare new cURL resource
$ch = curl_init($response_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);


curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json",
    "Content-Length: " . strlen($payload),
]);

// Submit the POST request
$result = curl_exec($ch);


// Close cURL session handle
curl_close($ch);

return json_encode(array(
    'status' => 200,
    'message' => ''
));

The issue I'm having is that the $result variable now holds the error I put above.

Does anyone happen to know what the issue could be?

Thanks!!

Upvotes: 1

Views: 102

Answers (1)

DanMossa
DanMossa

Reputation: 1092

Welp, it started to work again.

Must have been something on Slack's end. Weird because their status page didn't indicate anything

Upvotes: 1

Related Questions