theopenconversationkit / tock

Tock, the open source conversational AI toolkit.
https://doc.tock.ai
Apache License 2.0
477 stars 129 forks source link

[Web Connector] Ability to open a popup through URL buttons #1763

Open Fabilin opened 2 hours ago

Fabilin commented 2 hours ago

The web connector offers the ability to send a link to an arbitrary URL through an UrlButton: https://github.com/theopenconversationkit/tock/blob/903e3c242dd1e43d46ae0499733e6818a2958ffc/bot/connector-web-model/src/main/kotlin/ai/tock/bot/connector/web/send/UrlButton.kt#L22-L29

The existing target attribute can be used to make the button either open the link in a new tab (the default), or open in the current tab (specifically, it reflects the target attribute of the HTML anchor).

For some use cases, notably authentication flows, it can be helpful to instead open a popup window that will then close automatically. Currently, such a popup-opening button has to be implemented through a widget, but this requires copying existing behaviour from various frontend components.

Proposed solution

We could add a parameter to UrlButton which would enable the popup behaviour. In line with the existing target parameter, this new parameter could be a simple string matching the spec of windowFeatures. When this windowFeatures parameter gets specified, the tock-vue-kit and tock-react-kit would add a JS handler that cancels the default browser behaviour and opens the link in a new window. The implementation of this handler could be as simple as calling window.open(button.url, button.target, button.windowFeatures).

Thoughts @rkuffer @Benvii @assouktim?

rkuffer commented 2 hours ago

Sounds good to me