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

我的目标是能够使用斜杠命令打开对话框并将反馈处理到数据库中。我试图让对话框打开,但我收到有关斜杠命令的错误,其中显示“未找到”。

  • 我的应用程序设置有 API 和适当的 OAuth。

  • 我使用我的 php 页面的 url (domain.com/slash.php) 在我的应用程序中添加了一个斜杠命令

  • 斜杠命令使用以下代码设置。

当我从 slack 运行它时,我得到了输出

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

我尝试了一些调试并将trigger_id输出到屏幕上,发现trigger_id确实为null。我错过了什么才能通过这个?

我承认我是松弛领域的新手。我已经按照(我认为)松弛网站上关于正确设置应用程序的文档进行操作。

我是否遗漏了我的松弛应用程序设置或我的代码中导致此错误消息的内容?

预先感谢您的宝贵时间!

<?

$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);

?>


胡说叔叔
浏览 101回答 1
1回答

慕神8447489

要在 slack 中打开对话框,您可以使用此 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"});需要在您的 slack 应用程序中添加 view.open API 也为此使用以下步骤: 使用“Bot 用户 OAuth 访问令牌”,在“OAuth 和权限选项卡”中格式为 xoxb-xxxxx-xxxxx-xxxx。然后添加范围“views:open”并重新安装您的应用程序。然后尝试打开视图对话框。希望这会有所帮助。
打开App,查看更多内容
随时随地看视频慕课网APP