|
|
|
@ -7,24 +7,24 @@ const { domain } = require('../../config').server;
|
|
|
|
|
exports.newConnect = async ctx => {
|
|
|
|
|
try {
|
|
|
|
|
const { phone } = ctx.query;
|
|
|
|
|
const findSession = await getConnection({ sesson_id: phone, connect_domain: domain });
|
|
|
|
|
// todo: 只有一条
|
|
|
|
|
if (!isEmpty(findSession)) {
|
|
|
|
|
const { sesson_id: sessonId, status } = findSession[0];
|
|
|
|
|
if (['open', 'connecting'].includes(status)) {
|
|
|
|
|
const sock = sessionService.getSession(sessonId);
|
|
|
|
|
if (!isEmpty(sock)) {
|
|
|
|
|
return sock;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// const findSession = await getConnection({ sesson_id: phone, connect_domain: domain });
|
|
|
|
|
// // todo: 只有一条
|
|
|
|
|
// if (!isEmpty(findSession)) {
|
|
|
|
|
// const { sesson_id: sessonId, status } = findSession[0];
|
|
|
|
|
// if (['open', 'connecting'].includes(status)) {
|
|
|
|
|
// const sock = sessionService.getSession(sessonId);
|
|
|
|
|
// if (!isEmpty(sock)) {
|
|
|
|
|
// return sock;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
const whatsApp1 = await createWhatsApp(phone);
|
|
|
|
|
const existsSession = sessionService.getSession(phone);
|
|
|
|
|
let qr;
|
|
|
|
|
if (isEmpty(existsSession)) {
|
|
|
|
|
qr = await whatsApp1.start();
|
|
|
|
|
const { sessionId } = sessionService.createSession(phone, whatsApp1);
|
|
|
|
|
}
|
|
|
|
|
// if (isEmpty(existsSession)) {
|
|
|
|
|
qr = await whatsApp1.start();
|
|
|
|
|
const { sessionId } = sessionService.createSession(phone, whatsApp1);
|
|
|
|
|
// }
|
|
|
|
|
ctx.assert(whatsApp1, 503, 'No available connections');
|
|
|
|
|
return { qr, phone, sessionId: phone };
|
|
|
|
|
} catch (error) {
|
|
|
|
|