Php slackmessage对话框的Curl调用

Php slackmessage对话框的Curl调用,php,slack,slack-api,Php,Slack,Slack Api,谁能给我一个PHP中slack消息对话框的例子?如何对dialog.open方法进行curl调用?请提出建议。下面是一个简单的PHP示例,介绍如何基于斜杠命令创建对话框 请注意,您需要先创建并安装一个。您还需要向Slack应用程序添加一个脚本,该应用程序需要调用此脚本。最后,您需要手动将OAuth访问令牌从Slack应用添加到此脚本,以替换您的_令牌 该脚本将在Slack通道中打印API响应,因此您可以查看响应以及它们是否存在任何错误 执行斜杠命令以运行对话框 // define the dia

谁能给我一个PHP中slack消息对话框的例子?如何对dialog.open方法进行curl调用?请提出建议。

下面是一个简单的PHP示例,介绍如何基于斜杠命令创建对话框

请注意,您需要先创建并安装一个。您还需要向Slack应用程序添加一个脚本,该应用程序需要调用此脚本。最后,您需要手动将OAuth访问令牌从Slack应用添加到此脚本,以替换您的_令牌

该脚本将在Slack通道中打印API响应,因此您可以查看响应以及它们是否存在任何错误

执行斜杠命令以运行对话框

// define the dialog for the user (from Slack documentation example)
$dialog = [
  'callback_id' => 'ryde-46e2b0',
  'title' => 'Request a Ride',
  'submit_label' => 'Request',
  'elements' => [
    [
      'type' => 'text',
      'label' => 'Pickup Location',
      'name' => 'loc_origin'
    ],
    [
      'type' => 'text',
      'label' => 'Dropoff Location',
      'name' => 'loc_destination'
    ]
  ]
];

// get trigger ID from incoming slash request
$trigger = filter_input(INPUT_POST, "trigger_id");

// define POST query parameters
$query = [
    'token' => 'YOUR_TOKEN',
    'dialog' => json_encode($dialog),
    'trigger_id' => $trigger
];

// define the curl request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://slack.com/api/dialog.open');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

// set the POST query parameters
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query));

// execute curl request
$response = curl_exec($ch);

// close
curl_close($ch);

var_export($response);

Poja NikAM如果这个答案解决了你的问题,请考虑把它标记为解决方案。非常感谢。非常感谢。这对我很有帮助。太棒了!然后请您将这个答案标记为解决方案,这样问题就可以结束了吗?我在寻找与Node完全相同的节点,只是一个普通的请求。我不明白为什么Slack文档如此混乱