使用Slack斜杠命令找不到触发器ID?

时间:2020-05-22 16:43:52

标签: php slack-dialog

我的目标是能够使用斜杠命令打开对话框并将反馈处理到数据库中。我试图打开对话框,但遇到一条关于“表示未找到” trigger_id”的斜杠命令的错误。

  • 我的应用使用API​​和正确的OAuth进行了设置。
  • 我用我的php页面(domain.com/slash.php)的URL向我的应用程序添加了一个斜杠命令
  • 使用以下代码设置斜杠命令。

从松弛状态运行它时,我得到

的输出
'{"ok":false,"error":"invalid_arguments","response_metadata":{"messages":["[ERROR] missing required field: trigger_id"]}}'

我尝试了一些调试,并将trigger_id输出到屏幕上,发现trigger_id确实为空。我错过了什么呢?

我承认我是新手。我已经按照(我认为)从松弛网站上正确地设置了应用程序的文档。

我是否缺少我的松弛应用程序安装程序或代码中导致此错误消息的内容?

提前感谢您的宝贵时间!

<?
$command    = $_POST['command'];
$text       = $_POST['text'];
$token      = $_POST['token'];
$cn         = $_POST['channel_id'];
$user_id    = $_POST['user_id'];
$triggerid  = $_POST['trigger_id'];

// define the dialog for the user (from Slack documentation example)
$dialog = [
    'callback_id' => 'validres-3100',
    'title' => 'Test',
    'submit_label' => 'Submit',
    'elements' => [
        [
            'type' => 'text',
            'label' => 'Test Field 1',
            'name' => 'field_1'
        ],
        [
            'type' => 'text',
            'label' => 'Test Field 2',
            'name' => 'field_2'
        ]
    ]
];

// define POST query parameters
$query = [
        'token' => '<my api auth code>',
        'dialog' => json_encode($dialog),
        'trigger_id' => $triggerid
];

// 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);
?>

1 个答案:

答案 0 :(得分:0)

要以松弛状态打开对话框,可以使用此api“ https://slack.com/api/views.open”。 使用api,您需要发送仅3秒钟有效的触发器ID。 您的网址如下所示:https://slack.com/api/views.open?trigger_id=” +“ xxxx.xxxxxxxxx.xxxxxxxxxxxx” +“&view =您的数据”。 有了这个请求,您需要发送带有令牌的令牌,例如: (URL,“ POST”,{“ token”,“ xoxb-xxxxxx-xxxxx-xxxxxxx”});

还需要为此步骤在松弛应用中添加view.open API。 使用“ Bot用户OAuth访问令牌”,在“ OAuth和权限选项卡”中,格式为xoxb-xxxxx-xxxxx-xxxx。然后添加范围“ views:open”并以松弛状态重新安装您的应用程序。然后尝试获取打开视图对话框。

希望这会有所帮助。

相关问题