のチャネルにincoming webhooks
がインストールされています。 Attachments
はメッセージとともに送信する必要があり、PHP変数にはこれらのURLが保持されます。同様に、私はID's
をいくつか送って、いくつかのPHP変数で再び保持したいと思います。あなたは上記のattachments
変数に表示されている場合は先頭で宣言${testplan_name}
の値を印刷しようとするpretext
の変数内部があり、PHPは添付ファイルと変数の値を持つスラックメッセージを送信します
<?php
$testplan_name = $_POST[plan]; //test plan name coming from the client
$url1 = $_POST[run_url]; //run url coming from the client
$url2 = $_POST[plan_url]; //plan url coming from the client
$room = "random";
$icon_url = ":ghost:";
$username = "Test";
$attachments = array([
'fallback' => 'Hey! See this message',
'pretext' => 'Here is the plan name ${testplan_name}',
'color' => '#ff6600',
'fields' => array(
[
'title' => 'Run URL',
'value' => 'url1',
'short' => true
],
[
'title' => 'Build URL',
'value' => 'url2',
'short' => true
]
)
]);
$data = "payload=" . json_encode(array(
"channel" => "#{$room}",
"icon_emoji" => $icon_url,
"username" => $username,
"attachments" => $attachments
));
$url = "https://hooks.slack.com/services/XXXX/XXX/XXXXXXXXXXXXX"; //got from slack as a webhook URL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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);
echo var_dump($result);
if($result === false)
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
:ここに私のserver side PHP
コードです。しかし、それは動作していないようで、プログラムは余裕のあるチャンネルにメッセージを投稿できません。同様に、url1
とurl2
の値をattachments -> fields
の値(上記の印刷方法)で印刷したいとします。私が変数を使ってメッセージを投稿しているときに値を取得しようとしないと、プログラムはうまく動作します。これらの変数の値をメッセージにどのように出力するのですか?
(slack is a messaging platform for teams, if you don't know)