Skip to content

Commit 7fa7384

Browse files
authored
Support link click actions within Q chat (#44)
This PR handles the link click notifications, which includes aws/chat/linkClick, aws/chat/infoLinkClick and aws/chat/sourceLinkClick. We are showing a confirmation message box before opening links that are present in Chat UI.
1 parent 690f6ed commit 7fa7384

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
3+
package software.aws.toolkits.eclipse.amazonq.chat.models;
4+
5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
7+
public class InfoLinkClickParams {
8+
@JsonProperty("tabId")
9+
private String tabId;
10+
11+
@JsonProperty("link")
12+
private String link;
13+
14+
@JsonProperty("eventId")
15+
private String eventId;
16+
17+
public final String getTabId() {
18+
return tabId;
19+
}
20+
21+
public final void setTabId(final String tabId) {
22+
this.tabId = tabId;
23+
}
24+
25+
public final String getLink() {
26+
return link;
27+
}
28+
29+
public final void setLink(final String link) {
30+
this.link = link;
31+
}
32+
33+
public final String getEventId() {
34+
return eventId;
35+
}
36+
37+
public final void setEventId(final String eventId) {
38+
this.eventId = eventId;
39+
}
40+
}

plugin/src/software/aws/toolkits/eclipse/amazonq/util/PluginUtils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import org.eclipse.core.runtime.FileLocator;
1313
import org.eclipse.core.runtime.Path;
1414
import org.eclipse.core.runtime.Platform;
15+
import org.eclipse.jface.dialogs.MessageDialog;
1516
import org.eclipse.swt.graphics.Image;
17+
import org.eclipse.swt.widgets.Display;
1618
import org.eclipse.ui.PlatformUI;
1719
import org.osgi.framework.Bundle;
1820
import org.osgi.framework.FrameworkUtil;
@@ -98,4 +100,19 @@ public static void openWebpage(final String url) {
98100
PluginLogger.warn("Error while trying to open an external web page:", ex);
99101
}
100102
}
103+
104+
public static boolean showConfirmDialog(final String title, final String message) {
105+
final boolean[] result = new boolean[] {false};
106+
try {
107+
Display.getDefault().syncExec(new Runnable() {
108+
@Override
109+
public void run() {
110+
result[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), title, message);
111+
}
112+
});
113+
} catch (Exception ex) {
114+
PluginLogger.error(ex.getMessage());
115+
}
116+
return result[0];
117+
}
101118
}

plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQChatViewActionHandler.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult;
1515
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatUIInboundCommand;
1616
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatUIInboundCommandName;
17+
import software.aws.toolkits.eclipse.amazonq.chat.models.InfoLinkClickParams;
1718
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
1819
import software.aws.toolkits.eclipse.amazonq.util.JsonHandler;
1920
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
21+
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils;
2022
import software.aws.toolkits.eclipse.amazonq.util.ProgressNotficationUtils;
2123
import software.aws.toolkits.eclipse.amazonq.views.model.Command;
2224
import software.aws.toolkits.eclipse.amazonq.views.model.ParsedCommand;
@@ -54,6 +56,16 @@ public final void handleCommand(final ParsedCommand parsedCommand, final Browser
5456
chatCommunicationManager.sendMessageToChatUI(browser, chatUIInboundCommand);
5557
});
5658
break;
59+
case CHAT_INFO_LINK_CLICK:
60+
case CHAT_LINK_CLICK:
61+
case CHAT_SOURCE_LINK_CLICK:
62+
InfoLinkClickParams infoLinkClickParams = jsonHandler.convertObject(params, InfoLinkClickParams.class);
63+
var link = infoLinkClickParams.getLink();
64+
if (link == null || link.isEmpty()) {
65+
throw new IllegalArgumentException("Link parameter cannot be null or empty");
66+
}
67+
handleExternalLinkClick(link);
68+
break;
5769
case CHAT_READY:
5870
chatCommunicationManager.sendMessageToChatServer(browser, command, params);
5971
break;
@@ -67,6 +79,16 @@ public final void handleCommand(final ParsedCommand parsedCommand, final Browser
6779
}
6880
}
6981

82+
private void handleExternalLinkClick(final String link) {
83+
try {
84+
var result = PluginUtils.showConfirmDialog("Amazon Q", "Do you want to open the external website?\n\n" + link);
85+
if (result) {
86+
PluginUtils.openWebpage(link);
87+
}
88+
} catch (Exception ex) {
89+
PluginLogger.error("Failed to open url in browser", ex);
90+
}
91+
}
7092

7193
/*
7294
* Handles chat progress notifications from the Amazon Q LSP server. Sends a partial chat prompt message to the webview.

plugin/src/software/aws/toolkits/eclipse/amazonq/views/model/Command.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public enum Command {
1111
CHAT_READY("aws/chat/ready"),
1212
CHAT_TAB_ADD("aws/chat/tabAdd"),
1313
CHAT_SEND_PROMPT("aws/chat/sendChatPrompt"),
14+
CHAT_LINK_CLICK("aws/chat/linkClick"),
15+
CHAT_INFO_LINK_CLICK("aws/chat/infoLinkClick"),
16+
CHAT_SOURCE_LINK_CLICK("aws/chat/sourceLinkClick"),
1417
TELEMETRY_EVENT("telemetry/event"),
1518

1619
// Auth

0 commit comments

Comments
 (0)