jolicode/slack-php-api

Image Blocks in posts returning "invalid_blocks" error.

Closed this issue · 1 comments

Trying to add some images to chat post message and anytime I place the image blocks into the JSON object sent, I get an error of "invalid_blocks".

If I remove the 3 nodes with "type":"image" from the following JSON object, the post works just fine. I'm using $slackClient->chatPostMessage([...]); to send the message.

Using version 4.5.


Following is the JSON... I have obscured the image urls below.

[
  {
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": ":birthday: Today's Birthdays:"
    }
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": " - Employee 1 - 08/07\n"
    }
  },
  {
    "type": "divider"
  },
  {
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": ":star: Today's Work Anniversaries:"
    }
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "- Employee 2 - 17 Years\n"
    }
  },
  {
    "type": "divider"
  },
  {
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": ":no_entry_sign: On PTO Today:"
    }
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "- Employee 1 from 1:00 pm to 3:00 pm CST\n- Employee 3 - all day\n"
    }
  },
  {
    "type": "divider"
  },
  {
    "type": "header",
    "text": {
      "type": "plain_text",
      "text": ":newspaper: Today's Posts:"
    }
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "*Test Post #1* / _Employee 1_\n_This is just a test. It is only a test. _\r\nhttps://youtube.com\n\n"
    }
  },
  {
    "type": "image",
    "image_url": "https://s3.XXXXXX.com/uploads/64d146c7da835111239138.png",
    "alt_text": "Test Post #1"
  },
  {
    "type": "section",
    "text": {
      "type": "mrkdwn",
      "text": "*Test Post #1* / _Employee 1_\n_This is just a test. It is only a test. _\r\nhttps://youtube.com\n\n*Morning Post Test #2* / _Employee 1_\nThis is just a test. Trying out an image.\n\n"
    }
  },
  {
    "type": "image",
    "image_url": "https://s3.XXXXXX.com/uploads/64d1436751356448563628.jpg",
    "alt_text": "Morning Post Test #2"
  },
  {
    "type": "image",
    "image_url": "https://s3.XXXXXX.com/uploads/64d144e78c178766939002.jpeg",
    "alt_text": "Morning Post Test #2"
  },
  {
    "type": "divider"
  }
]

Stack Trace:

An error occurred when trying to run the Good Morning Slack Post: JoliCode\Slack\Exception\SlackErrorResponse: Slack returned error code "invalid_blocks" in /Users/grayloon/Sites/loons/grayloon/vendor/jolicode/slack-php-api/src/HttpPlugin/SlackErrorPlugin.php:41
Stack trace:
#0 /Users/grayloon/Sites/loons/grayloon/vendor/php-http/httplug/src/Promise/HttpFulfilledPromise.php(31): JoliCode\Slack\HttpPlugin\SlackErrorPlugin->JoliCode\Slack\HttpPlugin\{closure}(Object(Nyholm\Psr7\Response))
#1 /Users/grayloon/Sites/loons/grayloon/vendor/jolicode/slack-php-api/src/HttpPlugin/SlackErrorPlugin.php(42): Http\Client\Promise\HttpFulfilledPromise->then(Object(Closure))
#2 /Users/grayloon/Sites/loons/grayloon/vendor/php-http/client-common/src/PluginChain.php(44): JoliCode\Slack\HttpPlugin\SlackErrorPlugin->handleRequest(Object(Nyholm\Psr7\Request), Object(Closure), Object(Http\Client\Common\PluginChain))
#3 /Users/grayloon/Sites/loons/grayloon/vendor/php-http/client-common/src/Plugin/ErrorPlugin.php(62): Http\Client\Common\PluginChain->Http\Client\Common\{closure}(Object(Nyholm\Psr7\Request))
#4 /Users/grayloon/Sites/loons/grayloon/vendor/php-http/client-common/src/PluginChain.php(44): Http\Client\Common\Plugin\ErrorPlugin->handleRequest(Object(Nyholm\Psr7\Request), Object(Closure), Object(Http\Client\Common\PluginChain))
#5 /Users/grayloon/Sites/loons/grayloon/vendor/php-http/client-common/src/PluginChain.php(59): Http\Client\Common\PluginChain->Http\Client\Common\{closure}(Object(Nyholm\Psr7\Request))
#6 /Users/grayloon/Sites/loons/grayloon/vendor/php-http/client-common/src/PluginClient.php(87): Http\Client\Common\PluginChain->__invoke(Object(Nyholm\Psr7\Request))
#7 /Users/grayloon/Sites/loons/grayloon/vendor/jolicode/slack-php-api/generated/Runtime/Client/Client.php(82): Http\Client\Common\PluginClient->sendRequest(Object(Nyholm\Psr7\Request))
#8 /Users/grayloon/Sites/loons/grayloon/vendor/jolicode/slack-php-api/generated/Client.php(1806): JoliCode\Slack\Api\Runtime\Client\Client->executeEndpoint(Object(JoliCode\Slack\Api\Endpoint\ChatPostMessage), 'object')
#9 /Users/grayloon/Sites/loons/grayloon/src/Controller/MorningPostController.php(417): JoliCode\Slack\Api\Client->chatPostMessage(Array)
#10 /Users/grayloon/Sites/loons/grayloon/src/Controller/MorningPostController.php(390): App\Controller\MorningPostController->postToSlack('@rwade', Array)
#11 /Users/grayloon/Sites/loons/grayloon/vendor/symfony/http-kernel/HttpKernel.php(163): App\Controller\MorningPostController->goodMorningAction(Object(Symfony\Component\HttpFoundation\Session\Session))
#12 /Users/grayloon/Sites/loons/grayloon/vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#13 /Users/grayloon/Sites/loons/grayloon/vendor/symfony/http-kernel/Kernel.php(184): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#14 /Users/grayloon/Sites/loons/grayloon/public/index.php(25): Symfony\Component\HttpKernel\Kernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#15 /Users/grayloon/.composer/vendor/laravel/valet/server.php(234): require('/Users/grayloon...')
#16 {main}

Solved this myself. Had to do with public access on the images from S3. After adjusting some settings on the bucket ACL this began to work. Might suggest more verbose error messages. Thanks!