Skip to content

feat: ws support proxy #145

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: ws support proxy #145

wants to merge 1 commit into from

Conversation

xqin
Copy link

@xqin xqin commented Jun 28, 2025

Pass the agent parameter to WebSocket to support accessing the target service through a proxy.

full example code:

import axios from 'axios'
import { HttpsProxyAgent } from 'https-proxy-agent'
import Lark from '@larksuiteoapi/node-sdk'


const httpsAgent = new HttpsProxyAgent('http://127.0.0.1:8899')
const httpInstance = axios.create({
  proxy: false,
  httpsAgent,
})

httpInstance.interceptors.request.use((req) => {
    if (req.headers) {
        req.headers['User-Agent'] = 'oapi-node-sdk/1.0.0';
    }
    return req;
}, undefined, { synchronous: true })

httpInstance.interceptors.response.use((resp) => resp.data)



const larkConfig = {
  appId: 'xxxx',
  appSecret: 'yyyyyyy',
  httpInstance, // <!---  custom httpInstance
  loggerLevel: Lark.LoggerLevel.debug,
}


const wsClient = new Lark.WSClient(larkConfig)

wsClient.start({
  eventDispatcher: new Lark.EventDispatcher({}).register({
    'im.message.receive_v1': async (data) => {
      console.log('Received message:', JSON.stringify(data, null, 2))
    }
  })
})

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

Successfully merging this pull request may close these issues.

1 participant