@xuda.io/ai_module 1.1.4271 → 1.1.4272
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.mjs +29 -31
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4175,45 +4175,43 @@ export const create_conversation = async function (req, job_id, headers) {
|
|
|
4175
4175
|
};
|
|
4176
4176
|
const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, conversation_doc);
|
|
4177
4177
|
|
|
4178
|
-
let contact_uid_chat_conversation,
|
|
4178
|
+
let contact_uid_chat_conversation, contact_id, contact_doc;
|
|
4179
4179
|
|
|
4180
|
-
if (conversation_doc.reference_type === 'contacts') {
|
|
4180
|
+
if (conversation_doc.reference_type === 'contacts' && conversation_type === 'chat') {
|
|
4181
4181
|
// reference_id is the contact id
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
if (conversation_type === 'chat') {
|
|
4186
|
-
if (!receiver_contact_doc?.contact_uid) {
|
|
4187
|
-
throw new Error('chat conversation to non user recipient is not allowed');
|
|
4188
|
-
}
|
|
4182
|
+
contact_id = reference_id;
|
|
4183
|
+
contact_doc = await account_module.get_contact_info(uid, null, contact_id);
|
|
4189
4184
|
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
// write conversation to receiver
|
|
4185
|
+
if (!contact_doc?.contact_uid) {
|
|
4186
|
+
throw new Error('chat conversation to non user recipient is not allowed');
|
|
4187
|
+
}
|
|
4194
4188
|
|
|
4195
|
-
|
|
4189
|
+
if (contact_doc?.connection_stat !== 3) {
|
|
4190
|
+
throw new Error('chat conversation to the recipient is not available');
|
|
4191
|
+
}
|
|
4192
|
+
// write conversation to receiver
|
|
4196
4193
|
|
|
4197
|
-
|
|
4198
|
-
selector: {
|
|
4199
|
-
docType: 'contact',
|
|
4200
|
-
stat: 3,
|
|
4201
|
-
contact_uid: uid,
|
|
4202
|
-
},
|
|
4203
|
-
limit: 1,
|
|
4204
|
-
fields: ['_id'],
|
|
4205
|
-
};
|
|
4206
|
-
const sender_contact_ret = await account_module.find_contact_query(receiver_contact_doc.contact_uid, opt);
|
|
4194
|
+
// const sender_contact_ret = await db_module.get_couch_view_raw('xuda_contacts', 'contacts_by_contact_uid', { key: [receiver_contact_doc.contact_uid, uid] });
|
|
4207
4195
|
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4196
|
+
const opt = {
|
|
4197
|
+
selector: {
|
|
4198
|
+
docType: 'contact',
|
|
4199
|
+
stat: 3,
|
|
4200
|
+
contact_uid: uid,
|
|
4201
|
+
},
|
|
4202
|
+
limit: 1,
|
|
4203
|
+
fields: ['_id'],
|
|
4204
|
+
};
|
|
4205
|
+
const sender_contact_ret = await account_module.find_contact_query(receiver_contact_doc.contact_uid, opt);
|
|
4212
4206
|
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
contact_uid_chat_conversation = receiver_contact_doc.contact_uid;
|
|
4207
|
+
if (!sender_contact_ret?.docs?.length) {
|
|
4208
|
+
throw new Error('sender contact id not found');
|
|
4216
4209
|
}
|
|
4210
|
+
const sender_contact_id = sender_contact_ret?.docs[0]._id;
|
|
4211
|
+
|
|
4212
|
+
const app_id = await account_module.get_account_default_project_id(receiver_contact_doc.contact_uid);
|
|
4213
|
+
const save_ret = await db_module.save_app_couch_doc(app_id, { ...conversation_doc, ...{ uid: receiver_contact_doc.contact_uid, reference_id: sender_contact_id } });
|
|
4214
|
+
contact_uid_chat_conversation = receiver_contact_doc.contact_uid;
|
|
4217
4215
|
}
|
|
4218
4216
|
|
|
4219
4217
|
setTimeout(async () => {
|