Cannot open dialog

I am not sure what I am doing wrong, but I cant seem to open the dialog, but I am getting a {status: 'OK'} response…

Mattermost Version: 5.13.2

The post from the slash command is ephemeral

My slash command is working fine, and so is the interactive button (this is what should trigger the dialog to open).

Here is my code for the dialog to trigger. This req param is being passed from the action from clicking a button.

module.exports.addEmail = (req) => {
	let body = req.body;
	let data = JSON.stringify({
		trigger_id : body.trigger_id,
		url        : resolve(config.MM_ACTION_URL, '/mattermost/dialog'),
		dialog     : {
			title       : 'Email',
			callback_id : 'add_email',
			elements    : [
				{
					display_name : 'Email',
					name         : 'email',
					type         : 'text',
					subtype      : 'email',
					placeholder  : 'placeholder@example.com'
				}
			]
		}
	});
	mmRequest('post', 'actions/dialogs/open', data)
		.then((res) => {
			console.log(res);
		})
		.catch((error) => console.log(error));
};

On the server side, this is my code to add a little more context to my workflow.

app.post('/mattermost/actions', (req, res) => {
	// console.log(req.body);
	let action = req.body.context.action;
	if (action === 'add_email') {
		dialog.addEmail(req);
	}
});

app.post('/mattermost/dialog', (req, res) => {
	console.log(req.body);
	res.sendStatus(200);
});

And the function that is making the API call to the mattermost server is

module.exports.mmRequest = (method, url, data = {}) => {
	let c = {
		method  : method,
		baseURL : resolve(config.MATTERMOST_URL, 'api/v4/'),
		url     : url,
		data    : data,
		headers : {
			Authorization : `Bearer ${config.MM_ACCESS_TOKEN}`
		}
	};
	return new Promise((resolve, reject) => {
		Axios(c)
			.then((res) => {
				resolve(res.data);
			})
			.catch((error) => reject(error.response));
	});
};

In the console.log(res), I get a status OK message, but the dialog doesnt open… What am I doing wrong?

1 Like

I am facing the same issue right now. I send a dialog with correct trigger_id and receive 200/OK, but the dialog does not show. Did you find any solution until now?

Has this been fixed? Facing the same issue on 5.16.0
Getting 200/OK for the POST request to open dialog, but it doesn’t show up.

@securisec, @psharma9
There is a good example of how to display an interactive dialog in the demo plugin here?

It receives a slash command -> invokes the OpenInteractiveDialog PluginAPI that opens the dialog.

Hard to follow along the example mentioned in your post as there are pieces that are missing. Let me know if the demo plugin example helped.

@ali-farooq0
Thank you for your response. While /command should help us do it, my team is specifically looking to use buttons instead of /command.

The document says that we should be able to use it either way. Is a button click to provide the necessary trigger not sufficient?

@psharma9, I’ve uploaded an example where you can launch a dialog through an ephemeral message.

Example: https://github.com/mattermost/mattermost-plugin-demo/blob/403401ddf3c6a396ed53ba374e787b179887ea90/server/http_hooks.go#L185

Which will exhibit this behaviour:

If that was the desired behaviour, let me know and I can create a ticket to include that example in our demo plugin.

@psharma9 Did the example work for you?

Nice to meet you, I’m Japanese naoko1010hh.
I’m sorry, if you have any funny Japanese because I use Google interpreter

I did something similar in php but I can’t see the dialog via the button.

200 comes back with a callback but no dialog is displayed

The source code is here ↓

<?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) ) ) ); $contentss = file_get_contents("https:///api/v4/actions/dialogs/open", false, $context); It works fine for slash commands. In case of slash command, it is necessary to modify the source code from $contents["trigger_id"] to $_POST["trigger_id"]. If it is a slash command, it will return with POST If it's a button, it will come back with json. This difference is inconvenient

@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

Thank you very much!
I didn’t think I needed to “echo” the status at the end.
It works correctly by adding the line “echo”.
Thanks! !!

I am in trouble with this issue.

I would like to get dialog not via slash command but via interactive button.

I got trigger_id from interactive button and posted a dialog.
The return code was 200 but it does not open dialog.

Do you have some solution about this issue?

I had the same problem with Mattermost v7.9.1 (using the interactive button).
Does anyone know how to solve this?