|
|
@ -7,12 +7,13 @@ const { objectMapper, isEmpty } = require('../../utils/commons.util');
|
|
|
|
const { domain, name: domainName } = require('../../config').server;
|
|
|
|
const { domain, name: domainName } = require('../../config').server;
|
|
|
|
|
|
|
|
|
|
|
|
exports.newConnect = async ctx => {
|
|
|
|
exports.newConnect = async ctx => {
|
|
|
|
|
|
|
|
const { phone } = ctx.query;
|
|
|
|
|
|
|
|
const existsSession = sessionStore.getSession(phone);
|
|
|
|
|
|
|
|
if (!isEmpty(existsSession)) {
|
|
|
|
|
|
|
|
ctx.assert(null, 400, `WhatsApp ${phone} 已连接`);
|
|
|
|
|
|
|
|
// return { phone, session_id: phone, ...existsSession, stauts: 'open', wai_server: domain };
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { phone } = ctx.query;
|
|
|
|
|
|
|
|
const existsSession = sessionStore.getSession(phone);
|
|
|
|
|
|
|
|
if (!isEmpty(existsSession)) {
|
|
|
|
|
|
|
|
return { phone, session_id: phone, ...existsSession, stauts: 'open', wai_server: domain };
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const whatsApp1 = await createWhatsApp(phone);
|
|
|
|
const whatsApp1 = await createWhatsApp(phone);
|
|
|
|
ctx.assert(whatsApp1, 503, 'No available connections');
|
|
|
|
ctx.assert(whatsApp1, 503, 'No available connections');
|
|
|
|
whatsApp1.start();
|
|
|
|
whatsApp1.start();
|
|
|
|