Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate the possibility for a server to act as a client for connecting to external WebSockets #895

Closed
Badgerati opened this issue Jan 2, 2022 · 2 comments · Fixed by #968

Comments

@Badgerati
Copy link
Owner

Crazy idea here and early days, but what if we could have the Pode server act as a client and connect to other external WebSockets?

So far it seems possible, and it would include something like the following functions:

# connect to some external websocket (like slack for example)
Connect-PodeWebSocket -Name 'Slack' -Url '<url>' -ScriptBlock {} [-ArgumentList]

# like Send-PodeSignal, but for external WebSockets
Send-PodeWebSocket -Name 'Slack' -Message 'Message'

# close a current connection
Disconnect-PodeWebSocket -Name 'Slack'

# could be used to reset a connections URL (if it expires). possible? could require current logic?
Reset-PodeWebSocket -Name 'Slack' -ScriptBlock {}

The Connect-PodeWebSocket would open an async connection to some external websocket endpoint. It will then listen for requests, and call the scriptblock when received. You can send messages to the websocket using Send-PodeWebSocket.

This will happen in a seperate runspace, so it can be async. At the moment this runspace will only be created if any Connect- calls are made in the main Start-PodeServer scope, but I'm wondering if it's possible to create connections adhoc from anywhere 🤔

@Badgerati
Copy link
Owner Author

I've managed to get Pode to connect to other websockets, acting as a client. Running one Pode server as a websocket server, and then another connecting to the other server works fine.

At the moment I'm testing connecting to Slack's RTM websockets, to try and write a Slack bot. I can receive messages from Slack, but Slack doesn't seem to like the responses 🤔

@Badgerati
Copy link
Owner Author

Just testing and then documenting left 😄 this should now be in a good state to release as an experimental feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant