diff --git a/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js b/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js
index f06102998..445434c14 100644
--- a/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js
+++ b/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js
@@ -104,6 +104,8 @@ const WsQueryUrl = ({ item, collection, handleRun }) => {
className="w-full"
theme={displayedTheme}
onRun={handleRun}
+ collection={collection}
+ item={item}
/>
{
- return new Promise(async (resolve, reject) => {
- const ensureConnection = async () => {
- const connectionStatus = await isWsConnectionActive(item.uid);
- if (!connectionStatus.isActive) {
- await connectWS(item, collection, environment, runtimeVariables, { connectOnly: true });
- }
- };
- const { request } = item.draft ? item.draft : item;
- queueWsMessage(item, collection.uid, request.body.ws[0].content)
- .then((initialState) => {
- // Return an initial state object to update the UI
- // The real response data will be handled by event listeners
- resolve({
- ...initialState
- });
- })
- .catch((err) => reject(err));
- await ensureConnection();
+export const sendWsRequest = async (item, collection, environment, runtimeVariables) => {
+ const ensureConnection = async () => {
+ const connectionStatus = await isWsConnectionActive(item.uid);
+ if (!connectionStatus.isActive) {
+ await connectWS(item, collection, environment, runtimeVariables, { connectOnly: true });
+ }
+ };
+
+ await ensureConnection();
+
+ // Use queueWsMessage helper to queue all messages with proper variable interpolation
+ const result = await queueWsMessage(item, collection, environment, runtimeVariables, null);
+
+ if (result.success) {
+ return {};
+ } else {
+ throw new Error(result.error || 'Failed to queue messages');
+ }
+};
+
+/**
+ * Queues a message to an existing WebSocket connection with variable interpolation
+ * @param {Object} item - The request item
+ * @param {Object} collection - The collection object
+ * @param {Object} environment - The environment variables
+ * @param {Object} runtimeVariables - The runtime variables
+ * @param {string} messageContent - The message content to queue (or null to queue all messages)
+ * @returns {Promise