Cannot open dialog

@naoko1010hh

Your php code looks missing some parts, but does your script have code to send response?
In my environment, by adding echo $contents; in the end of script, I can show up dialog from button. My assumption is that response (e.g.: {"status":"ok"}) is necessary for showing up dialog from button.

The following is complete code on my environment.

<?php
  $json = file_get_contents("php://input");
  $contents = json_decode($json, true);
  error_log($contents["trigger_id"]);
  error_log($contents["channel_id"]);
  $data=[
    "trigger_id"=>$contents["trigger_id"],
    "url"=>"https://fascode.net/api/mattermost/twitter.php",
    "dialog"=>[
      "callback_id"=>"somecallbackid",
      "title"=>" @Fascode_SPTで返信する",
      "icon_url"=>"https://fascode.net/api/twitter/createimage.php?p=minasereneicon",
         "elements"=>[
             ["display_name"=>"返信ツイートURL", "name"=>"twurl", "type"=>"text", "subtype"=>"url", "default"=>$_GET["twurl"], "placeholder"=>"https://twitter.com/Fascode_SPT/status/1284175231540588544", "help_text"=>"何も変更しないでください", "optional"=>false, "min_length"=>0, "max_length"=>0, "data_source"=>"", "options"=>null],
            [ "display_name"=>"返信の内容", "name"=>"twtext", "type"=>"textarea", "subtype"=>"", "default"=>"", "placeholder"=>"ほげほげ", "help_text"=>"返信内容を記述してください", "optional"=>false, "min_length"=>1, "max_length"=>140, "data_source"=>"", "options"=>null ],
            [ "display_name"=>"返信に送付する画像 0", "name"=>"twimg0", "type"=>"text", "subtype"=>"url", "default"=>"", "placeholder"=>"https://fascode.net/img.png", "help_text"=>"", "optional"=>true, "min_length"=>0, "max_length"=>0, "data_source"=>"", "options"=>null ],
            [ "display_name"=>"返信に送付する画像 1", "name"=>"twimg1", "type"=>"text", "subtype"=>"url", "default"=>"", "placeholder"=>"https://fascode.net/img.png", "help_text"=>"", "optional"=>true, "min_length"=>0, "max_length"=>0, "data_source"=>"", "options"=>null ],
            [ "display_name"=>"返信に送付する画像 2", "name"=>"twimg2", "type"=>"text", "subtype"=>"url", "default"=>"", "placeholder"=>"https://fascode.net/img.png", "help_text"=>"", "optional"=>true, "min_length"=>0, "max_length"=>0, "data_source"=>"", "options"=>null ],
            [ "display_name"=>"返信に送付する画像 3", "name"=>"twimg3", "type"=>"text", "subtype"=>"url", "default"=>"", "placeholder"=>"https://fascode.net/img.png", "help_text"=>"", "optional"=>true, "min_length"=>0, "max_length"=>0, "data_source"=>"", "options"=>null ],
         ],
         "submit_label"=>"ツイートする",
         "notify_on_cancel"=>false,
         "state"=>"NODATA"
    ]
 ];
 foreach ($contents as $key => $value) {
     error_log($key." : ".$value);
 }
 $context = stream_context_create(
     array(
        'http' => array(
             'method'=> 'POST', 'header'=> 'Content-type: application/json;charset=UTF-8', 'content' => ''.json_encode($data)
        )
    )
 );
  $contents = file_get_contents("http://localhost:8065/api/v4/actions/dialogs/open", false, $context);
  echo $contents;
?>
1 Like