使用 PHP/Guzzle 打印 "Array" 将消息发送到松弛通道
sending message to slack channel using PHP/Guzzle prints "Array"
我正在尝试 post 到 Slack 频道,但它没有按预期工作。
我在 Slack 中收到的唯一消息是数组,因为文本的值是一个数组。当我理解他们的文档时,它不应该那样做。如果我将文本移动到数组的第一层,则会显示实际文本,所以我猜我的请求工作正常。我错过了什么?这是在 PHP 中使用 GuzzleHttpClient 完成的。
我的留言:
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'This is supposed to be my text'
]
];
我对 API 的请求:
$request = $client->post($url, [
RequestOptions::JSON => $messages
]);
您的结构不正确,请参阅文档:https://api.slack.com/messaging/composing/layouts#stack-of-blocks
应该是消息块数组,需要再嵌套一次
[
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'This is supposed to be my text'
]
]
];
它似乎不那么明显,但是您不能将用于其 API chat.postMessage
的消息格式用于传入的 webhook。两者的格式不同。
话虽如此,follow this documentation for webhook messages and it's respective formatting here。
您尝试做的是使用所谓的 "blocks",它似乎专用于他们的 API messaging。
如果您尝试在此 message builder (which is intended for webhooks), it will fail. But it will work on this message builder 上留言。
如果您希望消息显示在多行中,也许您可以使用换行符。参见 here。
正如@ncla 提到的,如果您使用 "Block UI" 元素,使用传入的 webhook API,您不能像 chat.postMessage
.
一样发送块
它在 Blocks 文档中并不明显,但在
Messages payload page 它指定您可以发送 blocks
属性。这将允许您使用 Blocks 结构。
我正在尝试 post 到 Slack 频道,但它没有按预期工作。 我在 Slack 中收到的唯一消息是数组,因为文本的值是一个数组。当我理解他们的文档时,它不应该那样做。如果我将文本移动到数组的第一层,则会显示实际文本,所以我猜我的请求工作正常。我错过了什么?这是在 PHP 中使用 GuzzleHttpClient 完成的。
我的留言:
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'This is supposed to be my text'
]
];
我对 API 的请求:
$request = $client->post($url, [
RequestOptions::JSON => $messages
]);
您的结构不正确,请参阅文档:https://api.slack.com/messaging/composing/layouts#stack-of-blocks
应该是消息块数组,需要再嵌套一次
[
[
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'This is supposed to be my text'
]
]
];
它似乎不那么明显,但是您不能将用于其 API chat.postMessage
的消息格式用于传入的 webhook。两者的格式不同。
话虽如此,follow this documentation for webhook messages and it's respective formatting here。
您尝试做的是使用所谓的 "blocks",它似乎专用于他们的 API messaging。
如果您尝试在此 message builder (which is intended for webhooks), it will fail. But it will work on this message builder 上留言。
如果您希望消息显示在多行中,也许您可以使用换行符。参见 here。
正如@ncla 提到的,如果您使用 "Block UI" 元素,使用传入的 webhook API,您不能像 chat.postMessage
.
它在 Blocks 文档中并不明显,但在
Messages payload page 它指定您可以发送 blocks
属性。这将允许您使用 Blocks 结构。