Does Pipedream Support a WSS Handshake?

This topic was automatically generated from Slack. You can find the original thread here.

does Pipedream support a wss handshake?

Pipedream does not explicitly mention support for WebSocket Secure (wss) handshakes in the provided documentation. However, Pipedream does support HTTP and HTTPS requests, and it is possible to work with WebSocket connections using custom code steps. To clarify your needs and provide a more accurate answer, could you please specify: 1. Are you looking to initiate a WebSocket connection from a Pipedream workflow? 2. Do you need to handle WebSocket events within a Pipedream workflow? 3. Any specific use case or example you have in mind? This information will help me guide you better.

I am trying to get this to work:

import { axios } from “@pipedream/platform”;

export default defineComponent({
props: {
humeApiKey: {
type: “string”,
label: “HUME API Key”,
secret: true,
},
},
async run({ steps, $ }) {
try {
const accessToken = await this.fetchAccessToken({
apiKey: this.humeApiKey,
$,
});

  const wsUrl = `wss://api.hume.ai/v1/evi/chats?access_token=${accessToken}`;
  const chatGroupId = await this.connectWebSocket(wsUrl, $);
  console.log('Chat Group ID:', chatGroupId);

  return { chatGroupId };
} catch (error) {
  if (error.response) {
    console.error("Data:", error.response.data);
    console.error("Status:", error.response.status);
    console.error("Headers:", error.response.headers);
  } else if (error.request) {
    console.error("Request:", error.request);
  } else {
    console.error("Error:", error.message);
  }
  console.error("Config:", error.config);
  throw error;
}

},
methods: {
async fetchAccessToken({ apiKey, $ }) {
const response = await axios($, {
method: “POST”,
url: “https://api.hume.ai/v0/auth/token”,
headers: {
“Content-Type”: “application/json”,
},
data: JSON.stringify({
apiKey,
}),
});
return response.data.access_token;
},
async connectWebSocket(wsUrl, $) {
return new Promise((resolve, reject) => {
const WebSocket = require(‘ws’);
const ws = new WebSocket(wsUrl);

    ws.on('open', () => {
      console.log('WebSocket connection opened');
    });

    ws.on('message', (message) => {
      const data = JSON.parse(message);

      if (data.type === 'chat_metadata') {
        console.log('Chat Metadata:', data);
        ws.close();
        resolve(data.chat_group_id);
      }
    });

    ws.on('error', (error) => {
      console.error('WebSocket error:', error);
      reject(error);
    });

    ws.on('close', () => {
      console.log('WebSocket connection closed');
    });
  });
},

},
});

To help you get your code working, let’s review and adjust your Pipedream component. We’ll ensure it follows the correct structure and syntax for Pipedream components. Here’s the revised version of your component: ``` import { axios } from “@pipedream/platform”; export default defineComponent({ props: { humeApiKey: { type: “string”, label: “HUME API Key”, secret: true, }, }, async run({ steps, $ }) { try { const accessToken = await this.fetchAccessToken({ apiKey: this.humeApiKey, $, }); const wsUrl = wss://api.hume.ai/v1/evi/chats?access_token=${accessToken}; const chatGroupId = await this.connectWebSocket(wsUrl, $); console.log(‘Chat Group ID:’, chatGroupId); return { chatGroupId }; } catch (error) { if (error.response) { console.error(“Data:”, error.response.data); console.error(“Status:”, error.response.status); console.error(“Headers:”, error.response.headers); } else if (error.request) { console.error(“Request:”, error.request); } else { console.error(“Error:”, error.message); } console.error(“Config:”, error.config); throw error; } }, methods: { async fetchAccessToken({ apiKey, $ }) { const response = await axios($, { method: “POST”, url: “https://api.hume.ai/v0/auth/token”, headers: { “Content-Type”: “application/json”, }, data: { apiKey, }, }); return response.access_token; }, async connectWebSocket(wsUrl, $) { return new Promise((resolve, reject) => { const WebSocket = require(‘ws’); const ws = new WebSocket(wsUrl); ws.on(‘open’, () => { console.log(‘WebSocket connection opened’); }); ws.on(‘message’, (message) => { const data = JSON.parse(message); if (data.type === ‘chat_metadata’) { console.log(‘Chat Metadata:’, data); ws.close(); resolve(data.chat_group_id); } }); ws.on(‘error’, (error) => { console.error('Web