leadguru-jobs 0.414.0__py3-none-any.whl → 0.415.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.
- {leadguru_jobs-0.414.0.dist-info → leadguru_jobs-0.415.0.dist-info}/METADATA +5 -10
- leadguru_jobs-0.415.0.dist-info/RECORD +26 -0
- lgt_jobs/__init__.py +4 -4
- lgt_jobs/jobs/analytics.py +1 -1
- lgt_jobs/jobs/archive_leads.py +2 -2
- lgt_jobs/jobs/bot_stats_update.py +9 -9
- lgt_jobs/jobs/chat_history.py +52 -57
- lgt_jobs/jobs/inbox_leads.py +6 -5
- lgt_jobs/jobs/mass_message.py +2 -2
- lgt_jobs/jobs/send_code.py +1 -1
- lgt_jobs/jobs/send_slack_message.py +24 -5
- lgt_jobs/jobs/update_slack_profile.py +14 -12
- lgt_jobs/jobs/user_balance_update.py +5 -5
- lgt_jobs/jobs/workspace_connect.py +5 -7
- lgt_jobs/main.py +11 -9
- lgt_jobs/runner.py +9 -6
- lgt_jobs/smtp.py +1 -1
- leadguru_jobs-0.414.0.dist-info/RECORD +0 -49
- lgt_jobs/lgt_common/__init__.py +0 -0
- lgt_jobs/lgt_common/discord_client/__init__.py +0 -0
- lgt_jobs/lgt_common/discord_client/discord_client.py +0 -62
- lgt_jobs/lgt_common/discord_client/methods.py +0 -16
- lgt_jobs/lgt_common/enums/__init__.py +0 -0
- lgt_jobs/lgt_common/enums/slack_errors.py +0 -6
- lgt_jobs/lgt_common/helpers.py +0 -18
- lgt_jobs/lgt_common/lgt_logging.py +0 -15
- lgt_jobs/lgt_common/pubsub/__init__.py +0 -0
- lgt_jobs/lgt_common/pubsub/command.py +0 -14
- lgt_jobs/lgt_common/pubsub/messages.py +0 -37
- lgt_jobs/lgt_common/pubsub/pubsubfactory.py +0 -51
- lgt_jobs/lgt_common/slack_client/__init__.py +0 -0
- lgt_jobs/lgt_common/slack_client/methods.py +0 -46
- lgt_jobs/lgt_common/slack_client/slack_client.py +0 -392
- lgt_jobs/lgt_common/slack_client/web_client.py +0 -167
- lgt_jobs/lgt_data/__init__.py +0 -0
- lgt_jobs/lgt_data/analytics.py +0 -723
- lgt_jobs/lgt_data/engine.py +0 -223
- lgt_jobs/lgt_data/enums.py +0 -68
- lgt_jobs/lgt_data/helpers.py +0 -2
- lgt_jobs/lgt_data/model.py +0 -956
- lgt_jobs/lgt_data/mongo_repository.py +0 -1015
- {leadguru_jobs-0.414.0.dist-info → leadguru_jobs-0.415.0.dist-info}/WHEEL +0 -0
- {leadguru_jobs-0.414.0.dist-info → leadguru_jobs-0.415.0.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: leadguru_jobs
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.415.0
|
4
4
|
Summary: LGT jobs builds
|
5
5
|
Author-email: developer@leadguru.co
|
6
6
|
Classifier: Development Status :: 5 - Production/Stable
|
@@ -17,8 +17,11 @@ Classifier: Intended Audience :: System Administrators
|
|
17
17
|
Classifier: Environment :: Console
|
18
18
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
19
19
|
Classifier: Topic :: Internet
|
20
|
-
Requires-Dist:
|
20
|
+
Requires-Dist: loguru
|
21
21
|
Requires-Dist: pydantic
|
22
|
+
Requires-Dist: cachetools >=3.1.0
|
23
|
+
Requires-Dist: leadguru-common ==0.383.0
|
24
|
+
Requires-Dist: leadguru-data ==0.390.0
|
22
25
|
Requires-Dist: wheel
|
23
26
|
Requires-Dist: setuptools
|
24
27
|
Requires-Dist: twine
|
@@ -28,12 +31,4 @@ Requires-Dist: pyyaml
|
|
28
31
|
Requires-Dist: pymongo
|
29
32
|
Requires-Dist: pytz
|
30
33
|
Requires-Dist: requests
|
31
|
-
Requires-Dist: mongoengine
|
32
|
-
Requires-Dist: google
|
33
|
-
Requires-Dist: google-cloud-pubsub
|
34
|
-
Requires-Dist: google-cloud-storage
|
35
|
-
Requires-Dist: websockets
|
36
|
-
Requires-Dist: aiohttp
|
37
|
-
Requires-Dist: nameparser
|
38
|
-
Requires-Dist: loguru
|
39
34
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
lgt_jobs/__init__.py,sha256=pzjunSJcWLeoxyN7wYDovpRgm0I68Dc0l7N1ykZaWxc,2131
|
2
|
+
lgt_jobs/basejobs.py,sha256=LPEclvY6fIG17YMGy9pRK0Q58n62gkI5W1BTK6R2p-c,1234
|
3
|
+
lgt_jobs/env.py,sha256=yzZ3Z2zAlA8B9FAY1GGEz2pkN_IiFqL-Reql1_Ub5qg,639
|
4
|
+
lgt_jobs/main.py,sha256=g9cIpahGFXZZv6fsftbjrOhQMrrD04kxKOuPpxKk3rk,1545
|
5
|
+
lgt_jobs/runner.py,sha256=Gqh5EBiV-XHkERmlD4PCrk-47VCLmwCs7Hl9pEo6kyI,2204
|
6
|
+
lgt_jobs/simple_job.py,sha256=sta7MP-57iwRewPycmTAc9dvSbocbGjWhb1QYYj7ccA,519
|
7
|
+
lgt_jobs/smtp.py,sha256=W9OIkckBORAWEsNgIG3nVKs6OTU6esZNnq09WDsj8Lc,1352
|
8
|
+
lgt_jobs/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
+
lgt_jobs/jobs/analytics.py,sha256=uL3_0xpS37VRJihTW1KiM_yhGGt1XV2yUNId_y-ISLk,972
|
10
|
+
lgt_jobs/jobs/archive_leads.py,sha256=wZ4LwbuC9G7NB16AO15YiMemEV40LoJVjd8VRqaFv9o,831
|
11
|
+
lgt_jobs/jobs/bot_stats_update.py,sha256=ZVeDxhVyDHiVFWIs1cGlEsu2WyF5P8mQClLT28C6hMA,6977
|
12
|
+
lgt_jobs/jobs/chat_history.py,sha256=skF7ssOzlNWiGeT27E3KF9DVKD5-fIp21M7GAq2kGwI,4758
|
13
|
+
lgt_jobs/jobs/inbox_leads.py,sha256=1vwV45RU3vHZnlnmLdW6Mo_ZADyjDS1z2gDPb9cggY8,4738
|
14
|
+
lgt_jobs/jobs/mass_message.py,sha256=sRKHYTQ5cwNep7gsuZTSpAEh8Y5d6PJ5lTQ6XxjsVSQ,2028
|
15
|
+
lgt_jobs/jobs/send_code.py,sha256=eLvp6KhOBp4DW-p162xojOm62J_Jzs6kfxutWhobE8U,826
|
16
|
+
lgt_jobs/jobs/send_slack_message.py,sha256=QiXbd2Ff61gby_IcBdTr9M3ATll3YvBuaKoegGG_Mnc,2672
|
17
|
+
lgt_jobs/jobs/update_slack_profile.py,sha256=NIIQRnmrWWYgYz12GWq5on12vaAaXsydQ2QDdeKV7SM,2646
|
18
|
+
lgt_jobs/jobs/user_balance_update.py,sha256=7LkcpKMilxqUcCS1_OW51qQnaXvGBavkj0a-0_-gK2g,2352
|
19
|
+
lgt_jobs/jobs/workspace_connect.py,sha256=YpLkhnr1cajkCioPojuavLPKPQIRmAKJtT6uoi5IBwM,6973
|
20
|
+
lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
|
+
lgt_jobs/services/web_client.py,sha256=D3y5KVVBk7mesRnsiByx4tFmNbfTOKOUoIp3VCHuk0I,1983
|
22
|
+
lgt_jobs/templates/new_message_mail_template.html,sha256=82XdDPtmkJVUWUcZtgd8bv_9-viAG2WWOnf3AhR6PeY,3635
|
23
|
+
leadguru_jobs-0.415.0.dist-info/METADATA,sha256=1R55ZFf6PzE53uv3uW9o5c1unCMmbheNjqqofrsf22E,1181
|
24
|
+
leadguru_jobs-0.415.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
25
|
+
leadguru_jobs-0.415.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
|
26
|
+
leadguru_jobs-0.415.0.dist-info/RECORD,,
|
lgt_jobs/__init__.py
CHANGED
@@ -6,7 +6,7 @@ from .jobs.analytics import (TrackAnalyticsJob, TrackAnalyticsJobData)
|
|
6
6
|
from .jobs.archive_leads import (ArchiveLeadsJob, ArchiveLeadsJobData)
|
7
7
|
from .jobs.bot_stats_update import (BotStatsUpdateJob, BotStatsUpdateJobData)
|
8
8
|
from .jobs.chat_history import (LoadChatHistoryJob, LoadChatHistoryJobData)
|
9
|
-
from .jobs.update_slack_profile import (
|
9
|
+
from .jobs.update_slack_profile import (UpdateUserSlackProfileJob, UpdateUserSlackProfileJobData)
|
10
10
|
from .jobs.mass_message import SendMassMessageSlackChannelJob, SendMassMessageSlackChannelJobData
|
11
11
|
from .basejobs import (BaseBackgroundJobData, BaseBackgroundJob, InvalidJobTypeException)
|
12
12
|
from .smtp import (SendMailJob, SendMailJobData)
|
@@ -20,7 +20,7 @@ jobs_map = {
|
|
20
20
|
"SendMailJob": SendMailJob,
|
21
21
|
"TrackAnalyticsJob": TrackAnalyticsJob,
|
22
22
|
"LoadChatHistoryJob": LoadChatHistoryJob,
|
23
|
-
"
|
23
|
+
"UpdateUserSlackProfileJob": UpdateUserSlackProfileJob,
|
24
24
|
"SendSlackMessageJob": SendSlackMessageJob,
|
25
25
|
"UpdateUserBalanceJob": UpdateUserBalanceJob,
|
26
26
|
"SendMassMessageSlackChannelJob": SendMassMessageSlackChannelJob,
|
@@ -33,7 +33,7 @@ __all__ = [
|
|
33
33
|
SendMailJob,
|
34
34
|
SimpleTestJob,
|
35
35
|
LoadChatHistoryJob,
|
36
|
-
|
36
|
+
UpdateUserSlackProfileJob,
|
37
37
|
TrackAnalyticsJob,
|
38
38
|
SendSlackMessageJob,
|
39
39
|
UpdateUserBalanceJob,
|
@@ -49,7 +49,7 @@ __all__ = [
|
|
49
49
|
SendMailJobData,
|
50
50
|
SimpleTestJobData,
|
51
51
|
LoadChatHistoryJobData,
|
52
|
-
|
52
|
+
UpdateUserSlackProfileJobData,
|
53
53
|
TrackAnalyticsJobData,
|
54
54
|
SendSlackMessageJobData,
|
55
55
|
UpdateUserBalanceJobData,
|
lgt_jobs/jobs/analytics.py
CHANGED
@@ -3,7 +3,7 @@ import datetime
|
|
3
3
|
from typing import Optional, List
|
4
4
|
from pydantic import BaseModel, conlist
|
5
5
|
from pymongo import MongoClient
|
6
|
-
from
|
6
|
+
from lgt.common.python.lgt_logging import log
|
7
7
|
from ..basejobs import BaseBackgroundJob, BaseBackgroundJobData
|
8
8
|
from ..env import mongo_connection_string
|
9
9
|
|
lgt_jobs/jobs/archive_leads.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
from abc import ABC
|
2
2
|
import datetime
|
3
|
-
from
|
3
|
+
from lgt_data.mongo_repository import UserLeadMongoRepository
|
4
4
|
from pydantic import BaseModel
|
5
5
|
from ..basejobs import BaseBackgroundJob, BaseBackgroundJobData
|
6
6
|
|
@@ -21,7 +21,7 @@ class ArchiveLeadsJob(BaseBackgroundJob, ABC):
|
|
21
21
|
def exec(self, data: ArchiveLeadsJobData):
|
22
22
|
lead_repository = UserLeadMongoRepository()
|
23
23
|
leads = lead_repository.get_leads(data.user_id, 0, 1000, archived=False,
|
24
|
-
to_date=datetime.datetime.
|
24
|
+
to_date=datetime.datetime.utcnow() - datetime.timedelta(days=90))
|
25
25
|
|
26
26
|
for lead in leads:
|
27
27
|
lead_repository.update_lead(data.user_id, lead.id, archived=True)
|
@@ -2,16 +2,16 @@ import random
|
|
2
2
|
import time
|
3
3
|
from abc import ABC
|
4
4
|
from typing import Optional
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
8
|
-
from
|
9
|
-
from
|
10
|
-
from
|
5
|
+
from lgt.common.python.discord_client.discord_client import DiscordClient
|
6
|
+
from lgt.common.python.helpers import get_formatted_bot_name
|
7
|
+
from lgt.common.python.slack_client.web_client import SlackWebClient
|
8
|
+
from lgt_data.enums import SourceType
|
9
|
+
from lgt_data.model import DedicatedBotModel, Server, Channel, DiscordUser
|
10
|
+
from lgt_data.mongo_repository import DedicatedBotRepository, UserMongoRepository
|
11
11
|
from pydantic import BaseModel
|
12
|
-
from
|
13
|
-
from
|
14
|
-
from
|
12
|
+
from lgt_data.analytics import get_bots_aggregated_analytics
|
13
|
+
from lgt.common.python.lgt_logging import log
|
14
|
+
from lgt.common.python.enums.slack_errors import SlackErrors
|
15
15
|
from ..basejobs import BaseBackgroundJob, BaseBackgroundJobData
|
16
16
|
|
17
17
|
"""
|
lgt_jobs/jobs/chat_history.py
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
import datetime
|
2
2
|
from abc import ABC
|
3
3
|
from typing import Optional, List
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
8
|
-
ChatRepository
|
4
|
+
from lgt.common.python.lgt_logging import log
|
5
|
+
from lgt.common.python.slack_client.web_client import SlackWebClient, SlackMessageConvertService
|
6
|
+
from lgt_data.model import SlackHistoryMessageModel, UserModel, UserContact
|
7
|
+
from lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository, UserContactsRepository
|
9
8
|
from pydantic import BaseModel
|
10
|
-
from
|
11
|
-
from lgt_jobs.runner import BaseBackgroundJob, BaseBackgroundJobData, BackgroundJobRunner
|
9
|
+
from ..runner import BackgroundJobRunner
|
12
10
|
from ..env import portal_url
|
11
|
+
from ..basejobs import BaseBackgroundJob, BaseBackgroundJobData
|
13
12
|
from ..smtp import SendMailJobData, SendMailJob
|
14
13
|
|
15
14
|
"""
|
@@ -28,76 +27,72 @@ class LoadChatHistoryJob(BaseBackgroundJob, ABC):
|
|
28
27
|
return LoadChatHistoryJobData
|
29
28
|
|
30
29
|
def exec(self, data: LoadChatHistoryJobData):
|
30
|
+
"""download chat history"""
|
31
31
|
user = UserMongoRepository().get(data.user_id)
|
32
|
-
|
33
|
-
if not
|
32
|
+
contacts = UserContactsRepository().find(user.id, with_chat_only=True, spam=False)
|
33
|
+
if not contacts:
|
34
34
|
return
|
35
|
+
|
36
|
+
log.info(f"[LoadChatHistoryJob]: processing {len(contacts)} contacts for user: {user.email}")
|
35
37
|
last_message = None
|
36
38
|
last_message_contact = None
|
37
|
-
for
|
38
|
-
|
39
|
-
if not contacts:
|
40
|
-
continue
|
41
|
-
|
42
|
-
log.info(f"[LoadChatHistoryJob]: processing {len(contacts)} contacts for user: {user.email}")
|
43
|
-
for contact in contacts:
|
44
|
-
message = LoadChatHistoryJob._update_history(user=user, contact=contact, bot=bot)
|
39
|
+
for contact in contacts:
|
40
|
+
message = LoadChatHistoryJob._update_history(user=user, contact=contact)
|
45
41
|
|
46
|
-
|
47
|
-
|
42
|
+
if not message:
|
43
|
+
continue
|
48
44
|
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
if not last_message:
|
46
|
+
last_message = message
|
47
|
+
last_message_contact = contact
|
52
48
|
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
if message.created_at > last_message.created_at and message.user == contact.sender_id:
|
50
|
+
last_message = message
|
51
|
+
last_message_contact = contact
|
56
52
|
|
57
53
|
has_to_be_notified = (not user.new_message_notified_at or
|
58
54
|
(last_message and last_message.created_at > user.new_message_notified_at))
|
59
55
|
|
60
56
|
if last_message and has_to_be_notified and last_message.user == last_message_contact.sender_id:
|
61
57
|
LoadChatHistoryJob._notify_about_new_messages(user, last_message_contact, data.template_path)
|
62
|
-
UserMongoRepository().set(data.user_id, new_message_notified_at=datetime.datetime.
|
58
|
+
UserMongoRepository().set(data.user_id, new_message_notified_at=datetime.datetime.utcnow())
|
63
59
|
|
64
60
|
@staticmethod
|
65
|
-
def
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
if not same_messages:
|
72
|
-
new_messages.append(message)
|
73
|
-
return new_messages
|
61
|
+
def _merge_chat_histories(contact: UserContact, messages: List[SlackHistoryMessageModel]):
|
62
|
+
for message in contact.chat_history:
|
63
|
+
if not [True for msg in messages if msg.ts == message.ts]: # Uniq messages
|
64
|
+
messages.append(message)
|
65
|
+
messages = sorted(messages, key=lambda d: d.created_at)
|
66
|
+
return messages
|
74
67
|
|
75
68
|
@staticmethod
|
76
|
-
def _update_history(user: UserModel, contact: UserContact
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
69
|
+
def _update_history(user: UserModel, contact: UserContact) -> Optional[SlackHistoryMessageModel]:
|
70
|
+
bot = DedicatedBotRepository().get_one(user_id=user.id, source_id=contact.source_id, only_valid=True)
|
71
|
+
if not bot:
|
72
|
+
return None
|
73
|
+
|
74
|
+
slack_client = SlackWebClient(bot.token, bot.cookies)
|
75
|
+
try:
|
76
|
+
history = slack_client.chat_history(contact.chat_id)
|
77
|
+
if not history.get('messages'):
|
84
78
|
return
|
79
|
+
except Exception as ex:
|
80
|
+
log.error(f'[LoadChatHistoryJob]: Failed to load chat for the contact: {contact.id}. ERROR: {str(ex)}')
|
81
|
+
return
|
85
82
|
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
if not history['ok']:
|
84
|
+
log.error(f'Failed to load chat for the contact: {contact.id}. ERROR: {history.get("error", "")}')
|
85
|
+
return
|
86
|
+
|
87
|
+
messages = [SlackMessageConvertService.from_slack_response(user.email, "slack_files", bot.token, m) for m in
|
88
|
+
history.get('messages', [])]
|
89
|
+
messages = LoadChatHistoryJob._merge_chat_histories(contact, messages)
|
90
|
+
chat_history = [message.to_dic() for message in messages]
|
91
|
+
if not chat_history:
|
92
|
+
return
|
89
93
|
|
90
|
-
|
91
|
-
|
92
|
-
return None
|
93
|
-
|
94
|
-
messages = [SlackMessageConvertService.from_slack_response(user.email, "slack_files",
|
95
|
-
bot.token, m, contact.sender_id, bot.id,
|
96
|
-
user.id, bot.cookies) for m in messages]
|
97
|
-
new_messages = LoadChatHistoryJob._get_new_messages(contact, bot, messages)
|
98
|
-
chat_history = [message.to_dic() for message in new_messages]
|
99
|
-
ChatRepository().upsert_messages(chat_history)
|
100
|
-
return new_messages[-1] if bot.associated_user != contact.sender_id else None
|
94
|
+
UserContactsRepository().update(user.id, contact.sender_id, chat_history=chat_history)
|
95
|
+
return messages[-1] if bot.associated_user != contact.sender_id else None
|
101
96
|
|
102
97
|
@staticmethod
|
103
98
|
def _notify_about_new_messages(user: UserModel, contact: UserContact, template_path: str):
|
lgt_jobs/jobs/inbox_leads.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
from abc import ABC
|
2
|
-
from
|
3
|
-
from
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from
|
2
|
+
from lgt.common.python.lgt_logging import log
|
3
|
+
from lgt.common.python.slack_client.web_client import SlackWebClient
|
4
|
+
from lgt_data.enums import DefaultBoards
|
5
|
+
from lgt_data.model import UserModel, DedicatedBotModel, SlackMemberInformation, UserLeadModel
|
6
|
+
from lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository, \
|
7
7
|
SlackContactUserRepository, BoardsMongoRepository, UserContactsRepository
|
8
8
|
from pydantic import BaseModel
|
9
9
|
from ..basejobs import BaseBackgroundJob, BaseBackgroundJobData
|
@@ -80,6 +80,7 @@ class InboxLeadsJob(BaseBackgroundJob, ABC):
|
|
80
80
|
@staticmethod
|
81
81
|
def create_people(slack_profile: dict, dedicated_bot: DedicatedBotModel):
|
82
82
|
member_info: SlackMemberInformation = SlackMemberInformation.from_slack_response(slack_profile,
|
83
|
+
dedicated_bot.source.source_name,
|
83
84
|
dedicated_bot.source)
|
84
85
|
SlackContactUserRepository().collection().update_one({"sender_id": member_info.sender_id,
|
85
86
|
"source.source_id": dedicated_bot.source.source_id},
|
lgt_jobs/jobs/mass_message.py
CHANGED
@@ -2,8 +2,8 @@ import time
|
|
2
2
|
from abc import ABC
|
3
3
|
from random import randint
|
4
4
|
from typing import Optional, Any
|
5
|
-
from
|
6
|
-
from
|
5
|
+
from lgt.common.python.slack_client.web_client import SlackWebClient
|
6
|
+
from lgt_data.mongo_repository import DedicatedBotRepository
|
7
7
|
from loguru import logger as log
|
8
8
|
from pydantic import BaseModel
|
9
9
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
lgt_jobs/jobs/send_code.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from abc import ABC
|
2
2
|
from typing import Optional
|
3
3
|
from loguru import logger as log
|
4
|
-
from
|
4
|
+
from lgt.common.python.slack_client.web_client import SlackWebClient
|
5
5
|
from pydantic import BaseModel
|
6
6
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
7
7
|
|
@@ -1,8 +1,10 @@
|
|
1
|
+
import datetime
|
1
2
|
from abc import ABC
|
2
3
|
from typing import Optional
|
3
|
-
from
|
4
|
-
from
|
5
|
-
from
|
4
|
+
from lgt.common.python.lgt_logging import log
|
5
|
+
from lgt.common.python.slack_client.web_client import SlackWebClient, SlackMessageConvertService
|
6
|
+
from lgt_data.mongo_repository import (UserMongoRepository, UserLeadMongoRepository,
|
7
|
+
DedicatedBotRepository, UserContactsRepository)
|
6
8
|
from pydantic import BaseModel
|
7
9
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
8
10
|
|
@@ -25,6 +27,7 @@ class SendSlackMessageJob(BaseBackgroundJob, ABC):
|
|
25
27
|
|
26
28
|
def exec(self, data: SendSlackMessageJobData):
|
27
29
|
user_leads_repository = UserLeadMongoRepository()
|
30
|
+
user = UserMongoRepository().get(data.user_id)
|
28
31
|
lead = user_leads_repository.get_lead(user_id=data.user_id, lead_id=data.lead_id)
|
29
32
|
if not lead:
|
30
33
|
return
|
@@ -41,6 +44,22 @@ class SendSlackMessageJob(BaseBackgroundJob, ABC):
|
|
41
44
|
|
42
45
|
channel_id = resp['channel']['id']
|
43
46
|
if data.files_ids:
|
44
|
-
slack_client.share_files(data.files_ids, channel_id, data.text)
|
47
|
+
resp = slack_client.share_files(data.files_ids, channel_id, data.text)
|
45
48
|
else:
|
46
|
-
slack_client.post_message(channel_id, data.text)
|
49
|
+
resp = slack_client.post_message(channel_id, data.text)
|
50
|
+
|
51
|
+
if not resp['ok']:
|
52
|
+
return log.warning(f"Unable to send message: {resp}")
|
53
|
+
|
54
|
+
message = resp.get('message') if 'message' in resp \
|
55
|
+
else slack_client.conversation_replies(channel_id, resp['file_msg_ts'])['messages'][0]
|
56
|
+
|
57
|
+
message_model = SlackMessageConvertService.from_slack_response(user.email, "slack_files", bot.token, message,
|
58
|
+
slack_client.client.cookies)
|
59
|
+
lead.chat_history.append(message_model)
|
60
|
+
chat_history = [message.to_dic() for message in lead.chat_history]
|
61
|
+
user_leads_repository.update_lead(user.id, lead.id, slack_channel=channel_id,
|
62
|
+
chat_history=chat_history, last_action_at=datetime.datetime.utcnow())
|
63
|
+
|
64
|
+
UserContactsRepository().update(user.id, lead.message.sender_id,
|
65
|
+
chat_id=channel_id, chat_history=chat_history)
|
@@ -1,32 +1,34 @@
|
|
1
1
|
from abc import ABC
|
2
|
-
from
|
3
|
-
from
|
4
|
-
from
|
5
|
-
from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository
|
2
|
+
from lgt.common.python.slack_client.slack_client import SlackClient
|
3
|
+
from lgt_data.model import UserModel
|
4
|
+
from lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository
|
6
5
|
from pydantic import BaseModel
|
7
6
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
8
7
|
|
8
|
+
"""
|
9
|
+
Update Slack User profile
|
10
|
+
"""
|
9
11
|
|
10
|
-
|
12
|
+
|
13
|
+
class UpdateUserSlackProfileJobData(BaseBackgroundJobData, BaseModel):
|
11
14
|
user_id: str
|
12
15
|
|
13
16
|
|
14
|
-
class
|
17
|
+
class UpdateUserSlackProfileJob(BaseBackgroundJob, ABC):
|
15
18
|
|
16
19
|
@property
|
17
20
|
def job_data_type(self) -> type:
|
18
|
-
return
|
21
|
+
return UpdateUserSlackProfileJobData
|
19
22
|
|
20
|
-
def exec(self, data:
|
23
|
+
def exec(self, data: UpdateUserSlackProfileJobData):
|
21
24
|
user = UserMongoRepository().get(data.user_id)
|
22
25
|
bots = DedicatedBotRepository().get_all(user_id=data.user_id, only_valid=True, include_deleted=False)
|
23
26
|
for bot in bots:
|
24
|
-
|
25
|
-
|
26
|
-
UpdateExternalUserProfileJob.__update_slack_profile(user, slack)
|
27
|
+
slack = SlackClient(bot.token, bot.cookies)
|
28
|
+
UpdateUserSlackProfileJob.__update_profile(user, slack)
|
27
29
|
|
28
30
|
@staticmethod
|
29
|
-
def
|
31
|
+
def __update_profile(user: UserModel, slack: SlackClient):
|
30
32
|
profile = slack.get_team_profile()
|
31
33
|
title_section_id = None
|
32
34
|
title_field_id = None
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import datetime
|
2
2
|
from abc import ABC
|
3
3
|
from typing import Optional
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
4
|
+
from lgt_data.engine import UserCreditStatementDocument
|
5
|
+
from lgt_data.enums import UserAccountState, UserAction
|
6
|
+
from lgt_data.model import UserModel
|
7
|
+
from lgt_data.mongo_repository import UserMongoRepository, to_object_id
|
8
8
|
from pydantic import BaseModel
|
9
9
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
10
10
|
|
@@ -49,7 +49,7 @@ class UpdateUserBalanceJob(BaseBackgroundJob, ABC):
|
|
49
49
|
# suspend account
|
50
50
|
if user.state != UserAccountState.Suspended.value:
|
51
51
|
UserMongoRepository().set(user.id, leads_proceeded=count,
|
52
|
-
credits_exceeded_at=datetime.datetime.
|
52
|
+
credits_exceeded_at=datetime.datetime.utcnow(),
|
53
53
|
state=UserAccountState.Suspended.value)
|
54
54
|
return
|
55
55
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
from abc import ABC
|
2
2
|
from typing import Dict
|
3
3
|
import requests
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
8
|
-
from
|
4
|
+
from lgt.common.python.helpers import update_credentials, get_formatted_bot_name
|
5
|
+
from lgt.common.python.slack_client.web_client import SlackWebClient
|
6
|
+
from lgt_data.enums import StatusConnection, SourceType
|
7
|
+
from lgt_data.model import UserWorkspace, SlackUser, DedicatedBotModel
|
8
|
+
from lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository
|
9
9
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
10
10
|
from .bot_stats_update import BotStatsUpdateJob, BotStatsUpdateJobData
|
11
11
|
from ..runner import BackgroundJobRunner
|
@@ -129,6 +129,4 @@ class ConnectSlackAccountJob(BaseBackgroundJob, ABC):
|
|
129
129
|
if auth.status_code == 200 and dedicated_bot.source.source_id not in user_workspaces_map.keys():
|
130
130
|
dedicated_bot.banned = True
|
131
131
|
dedicated_bot.invalid_creds = True
|
132
|
-
for server in dedicated_bot.servers:
|
133
|
-
server.deleted = True
|
134
132
|
dedicated_bots_repository.add_or_update(dedicated_bot)
|
lgt_jobs/main.py
CHANGED
@@ -2,11 +2,11 @@ import json
|
|
2
2
|
import sys
|
3
3
|
import threading
|
4
4
|
import time
|
5
|
-
from
|
6
|
-
from
|
7
|
-
from
|
8
|
-
|
9
|
-
from lgt_jobs import
|
5
|
+
from lgt_jobs import BackgroundJobRunner, jobs_map
|
6
|
+
from lgt.common.python.pubsub.pubsubfactory import PubSubFactory
|
7
|
+
from lgt.common.python.lgt_logging import log
|
8
|
+
|
9
|
+
from lgt_jobs import env
|
10
10
|
|
11
11
|
lock = threading.Lock()
|
12
12
|
|
@@ -35,10 +35,12 @@ def run_background_job_with_lock(message):
|
|
35
35
|
|
36
36
|
|
37
37
|
if __name__ == '__main__':
|
38
|
-
factory = PubSubFactory(project_id)
|
39
|
-
factory.create_topic_if_doesnt_exist(background_jobs_topic)
|
40
|
-
factory.create_subscription_if_doesnt_exist(background_jobs_subscriber, background_jobs_topic,
|
41
|
-
|
38
|
+
factory = PubSubFactory(env.project_id)
|
39
|
+
factory.create_topic_if_doesnt_exist(env.background_jobs_topic)
|
40
|
+
factory.create_subscription_if_doesnt_exist(env.background_jobs_subscriber, env.background_jobs_topic,
|
41
|
+
ack_deadline_seconds=600)
|
42
|
+
bot_subscription_path = factory.get_subscription_path(env.background_jobs_subscriber, env.background_jobs_topic)
|
43
|
+
|
42
44
|
factory.subscriber.subscribe(bot_subscription_path, callback=run_background_job_with_lock)
|
43
45
|
log.info(f'Listening for messages on {bot_subscription_path}')
|
44
46
|
while True:
|
lgt_jobs/runner.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import json
|
2
|
-
from datetime import datetime
|
3
|
-
from
|
4
|
-
from
|
2
|
+
from datetime import datetime
|
3
|
+
from lgt.common.python.pubsub.messages import _publish_message2_pubsub
|
4
|
+
from lgt_data.engine import DelayedJob
|
5
5
|
from .basejobs import InvalidJobTypeException, BaseBackgroundJobData, BaseBackgroundJob
|
6
6
|
from .env import background_jobs_topic
|
7
7
|
|
@@ -33,19 +33,22 @@ class BackgroundJobRunner:
|
|
33
33
|
|
34
34
|
@staticmethod
|
35
35
|
def submit_data(data: dict):
|
36
|
-
json_str = json.dumps(data,
|
36
|
+
json_str = json.dumps(data,
|
37
|
+
ensure_ascii=False,
|
38
|
+
default=datetime_converter)
|
37
39
|
BackgroundJobRunner.submit_json(json_str)
|
38
40
|
|
39
41
|
@staticmethod
|
40
42
|
def submit_json(json_str: str):
|
41
|
-
|
43
|
+
_publish_message2_pubsub(background_jobs_topic,
|
44
|
+
message_json=json_str)
|
42
45
|
|
43
46
|
@staticmethod
|
44
47
|
def schedule(jib: str, job: type, data: BaseBackgroundJobData, scheduled_at: datetime):
|
45
48
|
job_data = BaseBackgroundJob.dumps(job, data.model_dump())
|
46
49
|
DelayedJob(
|
47
50
|
jib=jib,
|
48
|
-
created_at=datetime.
|
51
|
+
created_at=datetime.utcnow(),
|
49
52
|
scheduled_at=scheduled_at,
|
50
53
|
job_type=job.__name__,
|
51
54
|
data=json.dumps(job_data, ensure_ascii=False, default=datetime_converter)
|
lgt_jobs/smtp.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
from abc import ABC
|
2
2
|
import smtplib
|
3
3
|
from pydantic import BaseModel
|
4
|
-
from
|
4
|
+
from lgt.common.python.lgt_logging import log
|
5
5
|
from .basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
6
6
|
from .env import smtp_login, smtp_password, smtp_host
|
7
7
|
|
@@ -1,49 +0,0 @@
|
|
1
|
-
lgt_jobs/__init__.py,sha256=B_w69fjqL6YCSZia0YFtmNx6xV0hriyMo9ZmONGzffg,2149
|
2
|
-
lgt_jobs/basejobs.py,sha256=LPEclvY6fIG17YMGy9pRK0Q58n62gkI5W1BTK6R2p-c,1234
|
3
|
-
lgt_jobs/env.py,sha256=yzZ3Z2zAlA8B9FAY1GGEz2pkN_IiFqL-Reql1_Ub5qg,639
|
4
|
-
lgt_jobs/main.py,sha256=SBav9t4vGpZOmGGP4ivFoxKtzdIAgHY0UMxfV19IXAM,1524
|
5
|
-
lgt_jobs/runner.py,sha256=MZ3_UvfyDSM707UI4uPDntlKKCXkIyN6h95D1i1SoQQ,2125
|
6
|
-
lgt_jobs/simple_job.py,sha256=sta7MP-57iwRewPycmTAc9dvSbocbGjWhb1QYYj7ccA,519
|
7
|
-
lgt_jobs/smtp.py,sha256=2PdCvyonQdyWZbPH9ozXFwapZp00fcxhBe7lQiVtMCo,1354
|
8
|
-
lgt_jobs/jobs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
lgt_jobs/jobs/analytics.py,sha256=iN1Z9ZtRHrpjzmSN4cbqwL6XzGWQYFmDBnBG-NvmlMc,974
|
10
|
-
lgt_jobs/jobs/archive_leads.py,sha256=Rc9MTWvVUCMEXi7mTrHWKZVyaRiseCFpHqUZcXekmIk,849
|
11
|
-
lgt_jobs/jobs/bot_stats_update.py,sha256=YlsD217E1L6mEkn0ggMKJk0Q0w9wHWlBFzWWFYED-Ws,7023
|
12
|
-
lgt_jobs/jobs/chat_history.py,sha256=QkB49zyGad1WMA-CKmdWgN6T8upRfDfyAAFmEyrtXqs,5338
|
13
|
-
lgt_jobs/jobs/inbox_leads.py,sha256=HGnhZEzMZw_Yzf40tQIRQc3E3QmcmEUyc1c5KTmJHFI,4646
|
14
|
-
lgt_jobs/jobs/mass_message.py,sha256=jLO-yykQzf-V7JY7a6PFwVoT4z91SJWN5UPrHj_xAP8,2039
|
15
|
-
lgt_jobs/jobs/send_code.py,sha256=ei5WHVpI2w2gv0JGU8wjg0HJYUO_OZqNJPm-W6yO1dA,828
|
16
|
-
lgt_jobs/jobs/send_slack_message.py,sha256=B14J7twVS7gjjjfKSLttrzbnJ3Eena4Ym4nf9t1s1Uk,1530
|
17
|
-
lgt_jobs/jobs/update_slack_profile.py,sha256=uA68Vp5BcU4YPJ0cX5YBkNMty1vmAEvColRZkZlVviA,2758
|
18
|
-
lgt_jobs/jobs/user_balance_update.py,sha256=hbUuOj-O0RqyHjZUrBwxiySFifyO3BJ_hKiTl-qM4iw,2397
|
19
|
-
lgt_jobs/jobs/workspace_connect.py,sha256=_IGxKWP2RHZZo750_R3sTHXcxO1-q8ZuyTbMyCxsEg8,7099
|
20
|
-
lgt_jobs/lgt_common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
|
-
lgt_jobs/lgt_common/helpers.py,sha256=tJNrKJYPa_MBmfRVrpHryoOWe4gnv7xOlmHuTh-bMBw,428
|
22
|
-
lgt_jobs/lgt_common/lgt_logging.py,sha256=wM68GBauFLWa5GfGDB1q14BuI-vypMs8RDGsgfAt5Go,541
|
23
|
-
lgt_jobs/lgt_common/discord_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
-
lgt_jobs/lgt_common/discord_client/discord_client.py,sha256=tvRn0P039Dp5d22-DivQhP2uQMC7ixZc7oe7IA4WrPE,2442
|
25
|
-
lgt_jobs/lgt_common/discord_client/methods.py,sha256=C46Vq9_-dlvs0nEW6ck8QvAmE_nPUfU89MJUhHaPMLk,391
|
26
|
-
lgt_jobs/lgt_common/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
27
|
-
lgt_jobs/lgt_common/enums/slack_errors.py,sha256=5VNbBaMKya2RIR5uyr3YI8N6Xll9WexItk7uJtoJ4NQ,142
|
28
|
-
lgt_jobs/lgt_common/pubsub/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
29
|
-
lgt_jobs/lgt_common/pubsub/command.py,sha256=tr7J51NGbt6Iq5CTEUyASu3o7KqP-Q64NfKaI1WVC64,278
|
30
|
-
lgt_jobs/lgt_common/pubsub/messages.py,sha256=rm7uKbxwDTWJqsVA8Kee-4YT58bThjCEV2Q0559Lrzg,1397
|
31
|
-
lgt_jobs/lgt_common/pubsub/pubsubfactory.py,sha256=7HAg_P2sZ6DDJkDyxzc4yI-i38bDSMxySulEGlHUhxc,2441
|
32
|
-
lgt_jobs/lgt_common/slack_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
33
|
-
lgt_jobs/lgt_common/slack_client/methods.py,sha256=-PxK8StkJ-dyACHdRRiQlRL2qaG9KEyWB7wo4eh7ifU,1506
|
34
|
-
lgt_jobs/lgt_common/slack_client/slack_client.py,sha256=fpfkk8uBMiTknMwgSNFGiGegN3qoJADJhjbpkpLKO8Y,15896
|
35
|
-
lgt_jobs/lgt_common/slack_client/web_client.py,sha256=d3fY_DxuJEr74_QWEitF_U-KAG3aRRyXZb6oH9Qxg80,6259
|
36
|
-
lgt_jobs/lgt_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
37
|
-
lgt_jobs/lgt_data/analytics.py,sha256=qo5nNFQxOTTk8i3tmCq0d3F9iaV9MTIR84SSi6uNrJ8,23427
|
38
|
-
lgt_jobs/lgt_data/engine.py,sha256=iTcLvU7QZvB14hcERQrxSql9cVEcMEzu_tUcWD2Z24A,8076
|
39
|
-
lgt_jobs/lgt_data/enums.py,sha256=A5nWwBgTVW7XaqL30NHNmO0SG_yeDk1dI-U5xrgU2zg,1552
|
40
|
-
lgt_jobs/lgt_data/helpers.py,sha256=58ycqKF1z5nAw0vs6yVCg-SQet107YHyKYXaQUc7M68,157
|
41
|
-
lgt_jobs/lgt_data/model.py,sha256=yiDPa2kgOARGMzbRc_heLpu1pRtt4xtf3VcYW7xsjBs,27999
|
42
|
-
lgt_jobs/lgt_data/mongo_repository.py,sha256=jVayqxxshJy4YF7DIlVTNdpuBc1eCTYhkT-INfl8qFs,37331
|
43
|
-
lgt_jobs/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
44
|
-
lgt_jobs/services/web_client.py,sha256=D3y5KVVBk7mesRnsiByx4tFmNbfTOKOUoIp3VCHuk0I,1983
|
45
|
-
lgt_jobs/templates/new_message_mail_template.html,sha256=82XdDPtmkJVUWUcZtgd8bv_9-viAG2WWOnf3AhR6PeY,3635
|
46
|
-
leadguru_jobs-0.414.0.dist-info/METADATA,sha256=mUtaEYXLyarGmxZE6Fr2PF0tj_CIzC1iKhhOEFgV8_I,1296
|
47
|
-
leadguru_jobs-0.414.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
48
|
-
leadguru_jobs-0.414.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
|
49
|
-
leadguru_jobs-0.414.0.dist-info/RECORD,,
|
lgt_jobs/lgt_common/__init__.py
DELETED
File without changes
|
File without changes
|