leadguru-jobs 0.621.0__py3-none-any.whl → 0.623.0__py3-none-any.whl

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: leadguru_jobs
3
- Version: 0.621.0
3
+ Version: 0.623.0
4
4
  Summary: LGT jobs builds
5
5
  Author-email: developer@leadguru.co
6
6
  Classifier: Development Status :: 5 - Production/Stable
@@ -13,15 +13,15 @@ lgt_jobs/assets/images/mail.png,sha256=eORzQcAMkFr7DjgtABVhJ_zFuXgO7OXv78lLF4b39
13
13
  lgt_jobs/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  lgt_jobs/jobs/analytics.py,sha256=IIsWt4A1qUw3w-S-8W16uKY1FRVWfXXA41_mu4uCNiM,979
15
15
  lgt_jobs/jobs/bot_stats_update.py,sha256=JRPPyqFvGHWuH_NQJNzIDy3DC0Joz14goNExqp-YUrw,8683
16
- lgt_jobs/jobs/chat_history.py,sha256=uHJhZ9euY49k7iai56PqGSOuWBSV6buKpwtSqHxbV8I,5134
16
+ lgt_jobs/jobs/chat_history.py,sha256=pwLGZyPS8N3h2eeoIIWGMwnzskPGFkPO3YVIY0KjQro,5245
17
17
  lgt_jobs/jobs/connect_sources.py,sha256=_eA86KnS3AC6YCI1xk7VCV7lFmPRxta-wUStfdmajQU,4790
18
- lgt_jobs/jobs/inbox_leads.py,sha256=OSX-FNx27gWEKNBBc-hyq2odCxXytz7WHtQJajtz274,5670
18
+ lgt_jobs/jobs/inbox_leads.py,sha256=SZGWtSYuWdruXl9m2dkk4XzSpVvVxjspi1X6RygR87I,4603
19
19
  lgt_jobs/jobs/load_slack_people.py,sha256=az3Pl8_0nUXizShpCksH6XMHFALLkta4QpMr_MkM9Io,3199
20
20
  lgt_jobs/jobs/mass_message.py,sha256=1mFcBlL2MhzLbj5yrd_NyJc7TXDWCcROAzGDnr0miMU,2035
21
21
  lgt_jobs/jobs/send_code.py,sha256=dIlLPkG3GgGKIEqGiElyzrtdrnJNTL1Ak2V0xnE-WIQ,824
22
- lgt_jobs/jobs/send_slack_message.py,sha256=_fuzqgspl7KRO6h4IRJya6sMT5JTqq_czodKB87GYqM,2451
22
+ lgt_jobs/jobs/send_slack_message.py,sha256=nNtuSsAIK5dzvP3B1G-BHNyk_LuZkHfsGmpXHHIqBb0,2329
23
23
  lgt_jobs/jobs/update_slack_profile.py,sha256=_ed0OhrVc1U-nE6dLckdmTmzZaxlK-y7h4S7SIpfEiA,3582
24
- lgt_jobs/jobs/user_balance_update.py,sha256=HxeEmDdloK9EcoEj1ybYTgxIkB0IQNLnss_kk3rLI1Q,2404
24
+ lgt_jobs/jobs/user_balance_update.py,sha256=1262PdJhsQ2oly2vJFT6IQWLKoPnBXmMkGBgu1U7sSs,2441
25
25
  lgt_jobs/jobs/workspace_connect.py,sha256=y48LGLtH7KxB-XAja9JOW4VFq4rzJh8cSf6heNBLSx0,7067
26
26
  lgt_jobs/lgt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
27
  lgt_jobs/lgt_common/helpers.py,sha256=3T47_Abw7datSIxVqIHTCB-sh-rnahWrmrFG8sSY9ZE,178
@@ -37,18 +37,20 @@ lgt_jobs/lgt_common/pubsub/pubsubfactory.py,sha256=rfUDooYuhBQ2pE9FdDxZOpXjbrvlp
37
37
  lgt_jobs/lgt_common/slack_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
38
  lgt_jobs/lgt_common/slack_client/methods.py,sha256=ctKF_1UHEmSWaRsoGEgMZicVabV7eEufZ7pjxdMAx8g,1455
39
39
  lgt_jobs/lgt_common/slack_client/slack_client.py,sha256=SR3YjJCJ-_8BPu29sFtF0ULijNL3QkBrvp_JXkm4DDk,13806
40
- lgt_jobs/lgt_common/slack_client/web_client.py,sha256=6ybC5v-oK-Kuat8qM2fskS6nCnA9cJ5U0yIKhp_Y4kM,4939
40
+ lgt_jobs/lgt_common/slack_client/web_client.py,sha256=WCu8mqYhauuxp9iDAMsjocchKD78iWdcnbu7Ozdyzq8,3448
41
41
  lgt_jobs/lgt_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
- lgt_jobs/lgt_data/analytics.py,sha256=fiN88zcIxs_bRMmXL7ftp4FvBeJ5I7QBPE4tbwKJ39E,21689
43
- lgt_jobs/lgt_data/engine.py,sha256=Rsbz-CApAo_TVDssdjBkv8v_fVOZm_Uh1S6W4fnaEWo,7728
44
- lgt_jobs/lgt_data/enums.py,sha256=jXrOcpy4awVuiZ51nSncfFospg0KsBZ4UwL650_VZVg,2259
45
- lgt_jobs/lgt_data/helpers.py,sha256=NDa-V5EYaJfkGoWsmQSwSe6N_jxNxs8tHRQzW1iST6k,480
46
- lgt_jobs/lgt_data/model.py,sha256=rbIrpXmubryaX79E5bPKVWTUgJVmeLDThtVUDP5tTOA,33350
47
- lgt_jobs/lgt_data/mongo_repository.py,sha256=SKIVxqc1u4I_uXTa3gSJRomRLt_6zKbQtLreC4EZZ8w,47111
42
+ lgt_jobs/lgt_data/analytics.py,sha256=vPKX-dXJzwg3T7w8Sx3a0mMi8HAlEwp8rcm1umE62mg,21681
43
+ lgt_jobs/lgt_data/engine.py,sha256=I9kz7Z6xzdrxN40S_9aYJMnoB54LpTA1Hk_yJYogohQ,7736
44
+ lgt_jobs/lgt_data/enums.py,sha256=3IV06umcBLXMCWnXUO66fyPM8IVwfCVbiSCjcwYMqCY,2238
45
+ lgt_jobs/lgt_data/helpers.py,sha256=Lg5aPM-EQiEcb4jFS9LoGbSwkB5-SYRnOutOHrOJKPA,611
46
+ lgt_jobs/lgt_data/model.py,sha256=PGAY24Uh7HnnEbaWTZe7nPkMaGy6Vb688q9Of8d2Yto,34592
47
+ lgt_jobs/lgt_data/mongo_repository.py,sha256=JdeWnmWI9SN-Z3mHW5B3-3gn6e0MUhKGRPTVxaT5Yow,46917
48
+ lgt_jobs/lgt_data/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
+ lgt_jobs/lgt_data/models/message_request.py,sha256=3m_2uSqnLUHrQbhTEKednoC0KuxAC5o2-LwONUAHCC8,367
48
50
  lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
- lgt_jobs/services/web_client.py,sha256=GLWsJkIC8rv6xLFaLwcMm4EwBlVDu0njORwkZqBJaE4,2086
51
+ lgt_jobs/services/web_client.py,sha256=oMyWJxwGeIe3f40fPT7xcisjDg3BhA3Ipf8dr1jVT-Y,1549
50
52
  lgt_jobs/templates/new_message.html,sha256=dZl8UmdAOOMq4nidvAgMFroSrTV7Pw0RWt2yLp_2idg,6989
51
- leadguru_jobs-0.621.0.dist-info/METADATA,sha256=ZgcCzckuAsnczf-2lEYpikDmv5DVmfaiWRLSLmBRfbw,1319
52
- leadguru_jobs-0.621.0.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
53
- leadguru_jobs-0.621.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
54
- leadguru_jobs-0.621.0.dist-info/RECORD,,
53
+ leadguru_jobs-0.623.0.dist-info/METADATA,sha256=HdXF8KzVG6SU0BV1YIgW-WhQzIRncF-ScnchOHXwLCo,1319
54
+ leadguru_jobs-0.623.0.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
55
+ leadguru_jobs-0.623.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
56
+ leadguru_jobs-0.623.0.dist-info/RECORD,,
@@ -2,10 +2,10 @@ from datetime import datetime, UTC
2
2
  from abc import ABC
3
3
  from typing import Optional, List
4
4
  import logging as log
5
- from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient, SlackMessageConvertService
5
+ from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient
6
6
  from lgt_jobs.lgt_data.model import ChatMessage, UserContact, DedicatedBotModel
7
7
  from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository, UserContactsRepository, \
8
- ChatRepository
8
+ ChatRepository, UserLeadMongoRepository
9
9
  from pydantic import BaseModel
10
10
  from lgt_jobs.lgt_data.enums import SourceType
11
11
  from lgt_jobs.runner import BaseBackgroundJob, BaseBackgroundJobData
@@ -23,6 +23,7 @@ class LoadChatHistoryJobData(BaseBackgroundJobData, BaseModel):
23
23
  class LoadChatHistoryJob(BaseBackgroundJob, ABC):
24
24
  chat_repo = ChatRepository()
25
25
  contacts_repo = UserContactsRepository()
26
+ user_leads_repo = UserLeadMongoRepository()
26
27
 
27
28
  @property
28
29
  def job_data_type(self) -> type:
@@ -97,14 +98,15 @@ class LoadChatHistoryJob(BaseBackgroundJob, ABC):
97
98
  if not messages:
98
99
  return None
99
100
 
100
- messages = [SlackMessageConvertService.from_slack_response(bot, m, contact.sender_id) for m in messages]
101
+ messages = [ChatMessage.from_slack_response(bot, m, contact.sender_id) for m in messages]
101
102
  new_messages = self._get_new_messages(contact, bot, messages)
102
103
  chat_history = [message.to_dic() for message in new_messages]
103
104
  self.chat_repo.upsert_messages(chat_history)
104
105
  if bot.associated_user != contact.sender_id and new_messages:
105
106
  log.info(f'[LoadChatHistoryJob]: New message. Sender id: {contact.sender_id}, bot id: {bot.id}')
106
- self.contacts_repo.update(contact.user_id, contact.sender_id, contact.source_id,
107
- last_message_at=datetime.now(UTC))
107
+ now = datetime.now(UTC)
108
+ self.contacts_repo.update(contact.user_id, contact.sender_id, contact.source_id, last_message_at=now)
109
+ self.user_leads_repo.update_many_by_sender_id(contact.sender_id, last_action_at=now)
108
110
  return new_messages[-1]
109
111
 
110
112
  return None
@@ -1,10 +1,10 @@
1
1
  from abc import ABC
2
2
  import logging as log
3
3
  from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient
4
- from lgt_jobs.lgt_data.enums import DefaultBoards
5
- from lgt_jobs.lgt_data.model import UserModel, DedicatedBotModel, SlackMemberInformation, UserLeadModel
4
+ from lgt_jobs.lgt_data.model import UserModel, DedicatedBotModel, SlackMemberInformation
5
+ from lgt_jobs.lgt_data.models.message_request import MessageRequest
6
6
  from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository, \
7
- SlackContactUserRepository, BoardsMongoRepository, UserContactsRepository
7
+ SlackContactUserRepository, UserContactsRepository, MessageRequestsRepository
8
8
  from pydantic import BaseModel
9
9
  from lgt_jobs.basejobs import BaseBackgroundJob, BaseBackgroundJobData
10
10
  from lgt_jobs.services.web_client import V3ServerClient
@@ -35,12 +35,9 @@ class InboxLeadsJob(BaseBackgroundJob, ABC):
35
35
  for dedicated_bot in dedicated_bots:
36
36
  self.create_inbox_leads(user, dedicated_bot)
37
37
 
38
- def create_inbox_leads(self, user: UserModel, dedicated_bot: DedicatedBotModel):
39
- inbox_board = BoardsMongoRepository().get(user.id, is_primary=True, name=DefaultBoards.Inbox.value)
40
- if not inbox_board:
41
- return
38
+ @staticmethod
39
+ def create_inbox_leads(user: UserModel, dedicated_bot: DedicatedBotModel):
42
40
  slack_client = SlackWebClient(dedicated_bot.token, dedicated_bot.cookies)
43
-
44
41
  attempt = 0
45
42
  conversations_list = []
46
43
  while attempt < 3:
@@ -85,21 +82,9 @@ class InboxLeadsJob(BaseBackgroundJob, ABC):
85
82
  slack_profile = slack_client.get_profile(sender_id).get('user')
86
83
  InboxLeadsJob.create_people(slack_profile, dedicated_bot)
87
84
 
88
- save_lead_response = self.v3_client.save_lead_from_contact(sender_id=sender_id,
89
- source_id=dedicated_bot.source.source_id,
90
- email=user.email,
91
- message=messages[0].get("text"))
92
- log.info(f"[InboxLeadsJob]: Save lead for user: {user.email}")
93
- if save_lead_response.status_code == 200:
94
- lead = UserLeadModel.from_dic(save_lead_response.json())
95
- self.v3_client.update_user_lead(lead.message.message_id, user.email,
96
- im_id, str(inbox_board[0].id), "Received")
97
- log.info(f"[InboxLeadsJob]: Added inbox lead {lead.id} for user: {user.email}")
98
-
99
- else:
100
- log.warning(f"[InboxLeadsJob]: Error to save lead from contact. "
101
- f"Details {save_lead_response.content}, "
102
- f"status code: {save_lead_response.status_code}")
85
+ log.info(f"[InboxLeadsJob]: New message request from {sender_id} for user: {user.email}")
86
+ message_request = MessageRequest.from_slack_response(dedicated_bot, messages[0], sender_id)
87
+ MessageRequestsRepository().insert(message_request.to_dic())
103
88
 
104
89
  @staticmethod
105
90
  def create_people(slack_profile: dict, dedicated_bot: DedicatedBotModel):
@@ -2,10 +2,9 @@ from datetime import datetime, UTC
2
2
  from abc import ABC
3
3
  from typing import Optional
4
4
  import logging as log
5
- from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient, SlackMessageConvertService
5
+ from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient
6
6
  from lgt_jobs.lgt_data.model import ChatMessage
7
- from lgt_jobs.lgt_data.mongo_repository import DedicatedBotRepository, UserContactsRepository, UserMongoRepository, \
8
- ChatRepository
7
+ from lgt_jobs.lgt_data.mongo_repository import DedicatedBotRepository, UserContactsRepository, ChatRepository
9
8
  from pydantic import BaseModel
10
9
  from lgt_jobs.basejobs import BaseBackgroundJobData, BaseBackgroundJob
11
10
 
@@ -31,7 +30,6 @@ class SendSlackMessageJob(BaseBackgroundJob, ABC):
31
30
  if not bot:
32
31
  return
33
32
 
34
- user = UserMongoRepository().get(bot.user_id)
35
33
  user_contacts_repository = UserContactsRepository()
36
34
  uc = user_contacts_repository.find_one(bot.user_id, sender_id=data.sender_id,
37
35
  source_id=bot.source.source_id)
@@ -54,6 +52,6 @@ class SendSlackMessageJob(BaseBackgroundJob, ABC):
54
52
  message = resp.get('message') if 'message' in resp \
55
53
  else slack_client.conversation_replies(channel_id, resp['file_msg_ts'])['messages'][0]
56
54
 
57
- message_model: ChatMessage = SlackMessageConvertService.from_slack_response(bot, message, data.sender_id)
55
+ message_model: ChatMessage = ChatMessage().from_slack_response(bot, message, data.sender_id)
58
56
  message_model.viewed = True
59
57
  ChatRepository().upsert_messages([message_model.to_dic()])
@@ -4,7 +4,8 @@ from typing import Optional
4
4
  from lgt_jobs.lgt_data.engine import UserCreditStatementDocument
5
5
  from lgt_jobs.lgt_data.enums import UserAccountState, UserAction
6
6
  from lgt_jobs.lgt_data.model import UserModel
7
- from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository, to_object_id
7
+ from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository
8
+ from lgt_jobs.lgt_data.helpers import to_object_id
8
9
  from pydantic import BaseModel
9
10
  from lgt_jobs.basejobs import BaseBackgroundJobData, BaseBackgroundJob
10
11
 
@@ -1,36 +1,6 @@
1
1
  from google.cloud import storage
2
- from datetime import datetime, timedelta
3
- from lgt_jobs.lgt_data.model import ChatMessage, LeadGuruFile, DedicatedBotModel
2
+ from datetime import timedelta
4
3
  from lgt_jobs.lgt_common.slack_client.slack_client import SlackClient
5
- from lgt_jobs.lgt_data.mongo_repository import to_object_id
6
-
7
-
8
- class SlackMessageConvertService:
9
- @staticmethod
10
- def from_slack_response(bot: DedicatedBotModel, message_data: dict, sender_id: str) -> ChatMessage:
11
- result = ChatMessage()
12
- result.sender_id = sender_id
13
- result.bot_id = to_object_id(bot.id)
14
- result.text = message_data.get('text', '')
15
- result.user = message_data.get('user', '')
16
- result.id = message_data.get('ts', '')
17
- result.attachments = message_data.get('attachments', [])
18
- result.files = []
19
- result.user_id = to_object_id(bot.user_id)
20
- result.source_id = bot.source.source_id
21
- if 'files' in message_data:
22
- for file in message_data.get('files'):
23
- if file.get('mode') != "tombstone" and file.get('url_private_download'):
24
- leadguru_file = LeadGuruFile()
25
- leadguru_file.id = file['id']
26
- leadguru_file.content_type = file['mimetype']
27
- leadguru_file.file_name = file['name']
28
- leadguru_file.blob_path = f'slack_files/{bot.user_name}/slack_files/{file["id"]}'
29
- result.files.append(leadguru_file)
30
-
31
- js_ticks = int(result.id.split('.')[0] + result.id.split('.')[1][3:])
32
- result.created_at = datetime.fromtimestamp(js_ticks / 1000.0)
33
- return result
34
4
 
35
5
 
36
6
  class SlackFilesClient:
@@ -4,7 +4,7 @@ from collections import OrderedDict
4
4
  from datetime import timedelta, datetime
5
5
  from bson import ObjectId
6
6
  from dateutil import tz
7
- from lgt_jobs.lgt_data.mongo_repository import to_object_id
7
+ from lgt_jobs.lgt_data.helpers import to_object_id
8
8
  from pymongo import MongoClient
9
9
 
10
10
  client = MongoClient(os.environ.get('MONGO_CONNECTION_STRING', 'mongodb://127.0.0.1:27017/'))
@@ -81,6 +81,7 @@ def _prepare_date_analytics_doc(doc, ordered_result_dict: Dict[str, int]):
81
81
  ordered_result_dict[str_date] = item["count"]
82
82
  return ordered_result_dict
83
83
 
84
+
84
85
  def get_channel_aggregated_analytics(from_date: datetime = None, to_date: datetime = None,
85
86
  bot_id: Optional[str | ObjectId] = None):
86
87
  pipeline = [
@@ -5,7 +5,7 @@ from datetime import datetime, UTC
5
5
  from bson import ObjectId
6
6
  from mongoengine import connect, Document, DateTimeField, StringField, IntField, ObjectIdField, ListField
7
7
  from typing import Dict, Tuple, Optional
8
- from .mongo_repository import to_object_id
8
+ from lgt_jobs.lgt_data.helpers import to_object_id
9
9
 
10
10
  connect(host=os.environ.get('MONGO_CONNECTION_STRING', 'mongodb://127.0.0.1:27017/'), db="lgt_admin", alias="lgt_admin")
11
11
 
@@ -50,7 +50,6 @@ class StatusConnection(str, Enum):
50
50
 
51
51
 
52
52
  class DefaultBoards(str, Enum):
53
- Inbox = 'Inbox',
54
53
  Primary = 'Primary board'
55
54
 
56
55
 
@@ -1,3 +1,5 @@
1
+ from bson import ObjectId
2
+
1
3
  from lgt_jobs.lgt_data.model import UserModel
2
4
  from lgt_jobs.lgt_data.mongo_repository import SubscriptionsRepository
3
5
 
@@ -9,3 +11,10 @@ def get_linkedin_search_contact(name: str):
9
11
  def get_help_text(user: UserModel):
10
12
  subscription = SubscriptionsRepository().find_one(id=user.subscription_id)
11
13
  return 'the onboarding call with us!' if subscription.trial else 'a call with us.'
14
+
15
+
16
+ def to_object_id(oid):
17
+ if isinstance(oid, ObjectId):
18
+ return oid
19
+ return ObjectId(oid)
20
+
@@ -6,6 +6,7 @@ from datetime import datetime, UTC, timedelta
6
6
  from typing import Optional, List
7
7
  from lgt_jobs.lgt_data.enums import UserRole, SourceType, FeaturesEnum, FeatureOptions, NotificationType
8
8
  from bson import ObjectId
9
+ from lgt_jobs.lgt_data.helpers import to_object_id
9
10
 
10
11
 
11
12
  class DictionaryModel(ABC):
@@ -361,7 +362,6 @@ class UserModel(BaseModel):
361
362
  self.company_web_site: str = ''
362
363
  self.company_description: str = ''
363
364
  self.position: str = ''
364
- # self.new_message_notified_at: Optional[datetime] = None # TODO: Move to settings
365
365
  self.leads_limit: Optional[int] = None
366
366
  self.leads_proceeded: Optional[int] = None
367
367
  self.leads_filtered: Optional[int] = None
@@ -705,6 +705,32 @@ class ChatMessage:
705
705
  setattr(model, k, v)
706
706
  return model
707
707
 
708
+ @classmethod
709
+ def from_slack_response(cls, bot: DedicatedBotModel, message_data: dict, sender_id: str) -> ChatMessage:
710
+ model = cls()
711
+ model.sender_id = sender_id
712
+ model.bot_id = to_object_id(bot.id)
713
+ model.text = message_data.get('text', '')
714
+ model.user = message_data.get('user', '')
715
+ model.id = message_data.get('ts', '')
716
+ model.attachments = message_data.get('attachments', [])
717
+ model.files = []
718
+ model.user_id = to_object_id(bot.user_id)
719
+ model.source_id = bot.source.source_id
720
+ if 'files' in message_data:
721
+ for file in message_data.get('files'):
722
+ if file.get('mode') != "tombstone" and file.get('url_private_download'):
723
+ leadguru_file = LeadGuruFile()
724
+ leadguru_file.id = file['id']
725
+ leadguru_file.content_type = file['mimetype']
726
+ leadguru_file.file_name = file['name']
727
+ leadguru_file.blob_path = f'slack_files/{bot.user_name}/slack_files/{file["id"]}'
728
+ model.files.append(leadguru_file)
729
+
730
+ js_ticks = int(model.id.split('.')[0] + model.id.split('.')[1][3:])
731
+ model.created_at = datetime.fromtimestamp(js_ticks / 1000.0)
732
+ return model
733
+
708
734
 
709
735
  class ScheduledChatMessage(ChatMessage):
710
736
  post_at: Optional[datetime]
File without changes
@@ -0,0 +1,10 @@
1
+ from lgt_jobs.lgt_data.model import ChatMessage, DedicatedBotModel
2
+
3
+
4
+ class MessageRequest(ChatMessage):
5
+ hidden: bool = False
6
+
7
+ @classmethod
8
+ def from_slack_response(cls, bot: DedicatedBotModel, message_data: dict, sender_id: str):
9
+ message = super().from_slack_response(bot, message_data, sender_id)
10
+ return message.from_dic(message.to_dic())
@@ -6,6 +6,7 @@ from dateutil import tz
6
6
  from pymongo import MongoClient, UpdateOne
7
7
  from bson.objectid import ObjectId
8
8
  from lgt_jobs.lgt_data.enums import SourceType
9
+ from lgt_jobs.lgt_data.helpers import to_object_id
9
10
  from lgt_jobs.lgt_data.model import (LeadModel, BaseModel, UserModel, UserResetPasswordModel, BoardModel, BoardedStatus,
10
11
  DedicatedBotModel, SlackMemberInformation, UserTemplateModel,
11
12
  ExtendedUserLeadModel, UserLeadModel, ExtendedLeadModel, UserContact, ChatMessage,
@@ -17,12 +18,6 @@ from collections import OrderedDict
17
18
  client = MongoClient(os.environ.get('MONGO_CONNECTION_STRING', 'mongodb://127.0.0.1:27017/'))
18
19
 
19
20
 
20
- def to_object_id(oid):
21
- if isinstance(oid, ObjectId):
22
- return oid
23
- return ObjectId(oid)
24
-
25
-
26
21
  class BaseMongoRepository:
27
22
  collection_name = ''
28
23
  database_name = 'lgt_admin'
@@ -35,7 +30,7 @@ class BaseMongoRepository:
35
30
  return client[self.database_name][collection_name]
36
31
 
37
32
  def insert_many(self, items):
38
- insert_items = map(lambda x: x.to_dic(), items)
33
+ insert_items = [item.to_dic() for item in items]
39
34
  self.collection().insert_many(insert_items)
40
35
 
41
36
  def insert(self, item: BaseModel):
@@ -85,7 +80,7 @@ class UserMongoRepository(BaseMongoRepository):
85
80
  if has_new_message:
86
81
  pipeline['notification_settings.incoming_messages.enabled'] = True
87
82
  pipeline['notification_settings.incoming_messages.need_to_notify'] = True
88
-
83
+
89
84
  if connected_slack_email:
90
85
  pipeline['slack_users.email'] = connected_slack_email
91
86
 
@@ -179,6 +174,10 @@ class UserLeadMongoRepository(BaseMongoRepository):
179
174
  self.collection().update_many({'message.source.source_id': source_id},
180
175
  {'$set': {'message.source': source_data}})
181
176
 
177
+ def update_many_by_sender_id(self, sender_id: str, **kwargs):
178
+ update_dict = {k: v for k, v in kwargs.items() if v is not None}
179
+ self.collection().update_many({'message.sender_id': sender_id}, {'$set': update_dict}, upsert=False)
180
+
182
181
  def get_many(self, ids: list, user_id):
183
182
  docs = self.collection().find({"id": {'$in': ids}, 'user_id': to_object_id(user_id)})
184
183
  leads = [ExtendedUserLeadModel.from_dic(lead) for lead in docs]
@@ -229,11 +228,11 @@ class UserLeadMongoRepository(BaseMongoRepository):
229
228
  configs = kwargs.get('config', None)
230
229
  bots_names = kwargs.get('bots_names', None)
231
230
  locations = kwargs.get('locations', None)
232
- dedicated_bots_ids = kwargs.get('dedicated_bots_ids', None)
233
231
  with_chat = kwargs.get('with_chat', None)
234
232
  leads_ids = kwargs.get('leads_ids', None)
235
233
  exclude_leads = kwargs.get('exclude_leads', None)
236
234
  exclude_senders = kwargs.get('exclude_senders', None)
235
+ deleted = kwargs.get('deleted', False)
237
236
 
238
237
  pipeline['message.profile.display_name'] = {
239
238
  "$ne": "Slackbot"
@@ -310,8 +309,8 @@ class UserLeadMongoRepository(BaseMongoRepository):
310
309
  if bots_names is not None:
311
310
  pipeline['message.name'] = {'$in': bots_names}
312
311
 
313
- if dedicated_bots_ids is not None:
314
- pipeline["message.dedicated_slack_options.bot_id"] = {"$in": dedicated_bots_ids}
312
+ pipeline['deleted'] = deleted
313
+
315
314
  return pipeline
316
315
 
317
316
  def get_daily_analytics_by_workspace(self, user_configs: list,
@@ -661,22 +660,6 @@ class SpamLeadsMongoRepository(LeadMongoRepository):
661
660
  return pipeline
662
661
 
663
662
 
664
- class GarbageLeadsMongoRepository(SpamLeadsMongoRepository):
665
- pass
666
-
667
- def __init__(self):
668
- super().__init__()
669
- self.collection_name = 'garbage_leads'
670
-
671
-
672
- class GarbageUserLeadsMongoRepository(UserLeadMongoRepository):
673
- pass
674
-
675
- def __init__(self):
676
- self.database_name = 'lgt_admin'
677
- self.collection_name = 'garbage_leads'
678
-
679
-
680
663
  class SpamUserLeadsMongoRepository(UserLeadMongoRepository):
681
664
  pass
682
665
 
@@ -1206,6 +1189,10 @@ class ChatRepository(BaseMongoRepository):
1206
1189
  self.collection().delete_one({"id": _id, 'user_id': to_object_id(user_id)})
1207
1190
 
1208
1191
 
1192
+ class MessageRequestsRepository(BaseMongoRepository):
1193
+ collection_name = 'message_requests'
1194
+
1195
+
1209
1196
  class UserVerificationMongoRepository(BaseMongoRepository):
1210
1197
  pass
1211
1198
 
@@ -1,5 +1,4 @@
1
1
  import requests
2
- from requests import Response
3
2
  from lgt_jobs.env import v3_server_host, v1_server_host, service_account_email, service_account_password
4
3
 
5
4
 
@@ -34,18 +33,6 @@ class V3ServerClient(BaseHttpClient):
34
33
  return requests.post(f'{v3_server_host}/{self.api_version}/user_leads/update',
35
34
  headers=headers, params=payload, json=update_lead_payload).json()
36
35
 
37
- def save_lead_from_contact(self, sender_id: str, source_id: str, email: str, message: str = None) -> Response:
38
- payload = {
39
- 'sender_id': sender_id,
40
- 'source_id': source_id,
41
- 'user_email': email,
42
- 'message': message,
43
- 'inbox': True
44
- }
45
- headers = self._create_default_headers()
46
- return requests.post(f'{v3_server_host}/{self.api_version}/user_leads/create',
47
- headers=headers, params=payload)
48
-
49
36
 
50
37
  class BillingServerClient:
51
38
  api_version = 'api'