@xuda.io/account_module 1.2.1937 → 1.2.1939

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.
Files changed (2) hide show
  1. package/index.mjs +117 -2
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2069,7 +2069,7 @@ setTimeout(async () => {
2069
2069
 
2070
2070
  let ret;
2071
2071
 
2072
- ret = await generate_contact_avatar({ uid, contact_id: 'cnt_c07049718613a11d164e90450d5f2742' });
2072
+ // ret = await generate_contact_avatar({ uid, contact_id: 'cnt_c07049718613a11d164e90450d5f2742' });
2073
2073
  // ret = await not_spam_contact({ uid, contact_id: 'cnt_c07049718613a11d164e90450d5f2742' });
2074
2074
  // ret = await get_account_ai_usage({ uid });
2075
2075
  // ret = await create_account_profile({ uid });
@@ -2140,7 +2140,7 @@ export const add_contact = async function (req, job_id, headers) {
2140
2140
 
2141
2141
  let is_spam = false;
2142
2142
  // let email_type_info;
2143
- let account_type_info;
2143
+ // let account_type_info;
2144
2144
  let business_info;
2145
2145
  let account_type;
2146
2146
  let cached_contact;
@@ -2762,6 +2762,28 @@ export const not_spam_contact = async function (req, job_id, headers) {
2762
2762
  var contact_doc = await get_contact(uid, contact_id);
2763
2763
  contact_doc.is_spam = false;
2764
2764
 
2765
+ //////////////////
2766
+ const is_business = await ai_module.is_business_contact(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2767
+ account_type = is_business ? 'business' : 'personal';
2768
+ if (is_business) {
2769
+ business_info = await ai_module.get_business_info(uid, '', email, account_profile_info, { light: true });
2770
+ if (business_info.business_name !== 'Not available') {
2771
+ business_has_person = await ai_module.is_business_contact_has_person(uid, email, name, metadata.subject, metadata.summarized_body, account_profile_info);
2772
+ } else {
2773
+ account_type = 'personal';
2774
+ business_info = undefined;
2775
+ }
2776
+ }
2777
+ if (_.isEmpty(cached_contact) && account_type === 'business' && !business_has_person) {
2778
+ if (!identifyPersonalProvider(business_info.business_domain)) {
2779
+ cached_contact = await get_xuda_cache(uid, 'contact', business_info.business_domain, 'metadata');
2780
+ } else {
2781
+ cached_contact = await get_xuda_cache(uid, 'contact', business_info.business_name, 'metadata');
2782
+ }
2783
+ }
2784
+
2785
+ ////////////////
2786
+
2765
2787
  await db_module.save_couch_doc_native('xuda_accounts', {
2766
2788
  _id: await _common.xuda_get_uuid('spam_whitelist'),
2767
2789
  uid,
@@ -2870,6 +2892,99 @@ export const generate_contact_avatar = async function (req, job_id, headers) {
2870
2892
  };
2871
2893
  }
2872
2894
  };
2895
+
2896
+ export const deep_research_contact = async function (req, job_id, headers) {
2897
+ const email_module = await import(`${module_path}/email_module/index.mjs`);
2898
+ // const ai_module = await import(`${module_path}/ai_module/index.mjs`);
2899
+
2900
+ const { contact_id, uid } = req;
2901
+ const account_profile_info = await get_active_account_profile_info(uid);
2902
+ try {
2903
+ var contact_doc = await get_contact(uid, contact_id);
2904
+ contact_doc.is_spam = false;
2905
+
2906
+ await db_module.save_couch_doc_native('xuda_accounts', {
2907
+ _id: await _common.xuda_get_uuid('spam_whitelist'),
2908
+ uid,
2909
+ docType: 'spam_whitelist',
2910
+ email: contact_doc.email,
2911
+ date_created_ts: Date.now(),
2912
+ stat: 3,
2913
+ });
2914
+
2915
+ const contact_save_ret = await save_contact(uid, contact_doc);
2916
+ await delete_xuda_cache(contact_doc);
2917
+ set_contact_profile_picture(uid, contact_doc._id, {}, job_id, headers, account_profile_info, false);
2918
+
2919
+ // find contact emails , set status to 1
2920
+
2921
+ const emails = await db_module.find_app_couch_query(account_profile_info.app_id, {
2922
+ selector: {
2923
+ docType: 'email',
2924
+ contact_id,
2925
+ stat: 3,
2926
+ process_stat: 'partial',
2927
+ },
2928
+ });
2929
+
2930
+ for await (let email of emails.docs) {
2931
+ const app_id = await get_account_default_project_id(uid);
2932
+ if (email.conversation_id) {
2933
+ db_module.delete_app_couch_doc(app_id, email.conversation_id);
2934
+ email.conversation_id = null;
2935
+ }
2936
+ if (email.conversation_item_id) {
2937
+ db_module.delete_app_couch_doc(app_id, email.conversation_item_id);
2938
+ email.conversation_item_id = null;
2939
+ }
2940
+ const save_ret = await db_module.save_app_couch_doc_native(app_id, email);
2941
+
2942
+ // save attachments
2943
+ // summarized_body
2944
+ req.uid = email.uid;
2945
+ req.email_id = email._id;
2946
+ await email_module.process_pending_email(req, job_id, headers);
2947
+
2948
+ // await process_email(email.email_account_id, profile, uid, email._id, job_id, headers, null, true);
2949
+ }
2950
+
2951
+ // const conversations = await db_module.find_app_couch_query(account_profile_info.app_id, {
2952
+ // selector: {
2953
+ // docType: 'chat_conversation',
2954
+ // reference_id: contact_id,
2955
+ // stat: 3,
2956
+
2957
+ // process_stat: 'partial',
2958
+ // },
2959
+ // });
2960
+
2961
+ // for await (let conversation of conversations.docs) {
2962
+ // await ai_module.process_conversation(uid, conversation._id, account_profile_info, job_id, headers);
2963
+ // await ai_module.update_conversation_mood_level(uid, [{ uid: account_profile_info.uid, contact_id }], conversation._id, conversation.prompt, null, reference_id, conversation.reference_type === 'contacts', account_profile_info);
2964
+
2965
+ // const conversation_items = await db_module.find_app_couch_query(account_profile_info.app_id, {
2966
+ // selector: {
2967
+ // docType: 'chat_conversation_item',
2968
+ // conversation_id: conversation._id,
2969
+ // stat: 3,
2970
+ // process_stat: 'partial',
2971
+ // },
2972
+ // });
2973
+ // for await (let conversation_item of conversation_items.docs) {
2974
+ // }
2975
+ // }
2976
+
2977
+ // update_conversation_mood_level
2978
+ // attachment_handler
2979
+
2980
+ return contact_save_ret;
2981
+ } catch (err) {
2982
+ return {
2983
+ code: -24,
2984
+ data: err.message,
2985
+ };
2986
+ }
2987
+ };
2873
2988
  //////// PROFILES //////////////
2874
2989
 
2875
2990
  export const get_pending_share_profile_in = async function (uid, _id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/account_module",
3
- "version": "1.2.1937",
3
+ "version": "1.2.1939",
4
4
  "description": "Xuda Account Server Module",
5
5
  "main": "index.mjs",
6
6
  "dependencies": {