-
-
Notifications
You must be signed in to change notification settings - Fork 350
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Really need proxy support and saving it in the session. I suppose you need to add proxy
field into the sessions/add
endpoint. And add an endpoint like sessions/<:session>/update
with field proxy
that updates proxy in the session to the one passed.
I've done it myself so far. Everything works, but I'm not sure if the proxy is being set. Can you check it right?
// src/wa.ts
import { HttpsProxyAgent } from 'https-proxy-agent';
import { SocksProxyAgent } from 'socks-proxy-agent';
type createSessionOptions = {
sessionId: string;
res?: Response;
proxy?: string;
SSE?: boolean;
socketConfig?: SocketConfig;
};
export async function createSession(options: createSessionOptions) {
const { sessionId, res, proxy = false, SSE = false, socketConfig } = options;
....
const setProxy = (socket, proxy) => {
if (proxy) {
// replace 'socks5' -> 'socks'
const proxyData = proxy.replace(/(?<=[a-z])(\d?)(?=://)/g, '');
let agent;
switch (true) {
case /^socks/.test(proxyData):
agent = SocksProxyAgent(proxyData);
break;
case /^http/.test(proxyData):
agent = HttpsProxyAgent(proxyData);
break;
default:
return;
}
Object.assign(socket, { agent });
};
const socket = makeWASocket({
// your code here
});
...
}
setProxy(socket, proxy);
I also added a proxy field to the sessions/add
endpoint. In the MySQL database the proxy is inserted into the data
column.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request