leadguru-jobs 0.415.0__py3-none-any.whl → 0.416.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.415.0.dist-info → leadguru_jobs-0.416.0.dist-info}/METADATA +10 -5
- leadguru_jobs-0.416.0.dist-info/RECORD +49 -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 +57 -52
- lgt_jobs/jobs/inbox_leads.py +5 -6
- lgt_jobs/jobs/mass_message.py +2 -2
- lgt_jobs/jobs/send_code.py +1 -1
- lgt_jobs/jobs/send_slack_message.py +5 -24
- lgt_jobs/jobs/update_slack_profile.py +12 -14
- lgt_jobs/jobs/user_balance_update.py +5 -5
- lgt_jobs/jobs/workspace_connect.py +7 -5
- 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 +62 -0
- lgt_jobs/lgt_common/discord_client/methods.py +16 -0
- lgt_jobs/lgt_common/enums/__init__.py +0 -0
- lgt_jobs/lgt_common/enums/slack_errors.py +6 -0
- lgt_jobs/lgt_common/helpers.py +18 -0
- lgt_jobs/lgt_common/lgt_logging.py +15 -0
- lgt_jobs/lgt_common/pubsub/__init__.py +0 -0
- lgt_jobs/lgt_common/pubsub/command.py +14 -0
- lgt_jobs/lgt_common/pubsub/messages.py +37 -0
- lgt_jobs/lgt_common/pubsub/pubsubfactory.py +51 -0
- lgt_jobs/lgt_common/slack_client/__init__.py +0 -0
- lgt_jobs/lgt_common/slack_client/methods.py +46 -0
- lgt_jobs/lgt_common/slack_client/slack_client.py +392 -0
- lgt_jobs/lgt_common/slack_client/web_client.py +167 -0
- lgt_jobs/lgt_data/__init__.py +0 -0
- lgt_jobs/lgt_data/analytics.py +723 -0
- lgt_jobs/lgt_data/engine.py +223 -0
- lgt_jobs/lgt_data/enums.py +68 -0
- lgt_jobs/lgt_data/helpers.py +2 -0
- lgt_jobs/lgt_data/model.py +955 -0
- lgt_jobs/lgt_data/mongo_repository.py +1013 -0
- lgt_jobs/main.py +9 -11
- lgt_jobs/runner.py +6 -9
- lgt_jobs/smtp.py +1 -1
- leadguru_jobs-0.415.0.dist-info/RECORD +0 -26
- {leadguru_jobs-0.415.0.dist-info → leadguru_jobs-0.416.0.dist-info}/WHEEL +0 -0
- {leadguru_jobs-0.415.0.dist-info → leadguru_jobs-0.416.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.416.0
|
4
4
|
Summary: LGT jobs builds
|
5
5
|
Author-email: developer@leadguru.co
|
6
6
|
Classifier: Development Status :: 5 - Production/Stable
|
@@ -17,11 +17,8 @@ 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: cachetools ==3.1.0
|
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
|
25
22
|
Requires-Dist: wheel
|
26
23
|
Requires-Dist: setuptools
|
27
24
|
Requires-Dist: twine
|
@@ -31,4 +28,12 @@ Requires-Dist: pyyaml
|
|
31
28
|
Requires-Dist: pymongo
|
32
29
|
Requires-Dist: pytz
|
33
30
|
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
|
34
39
|
|
@@ -0,0 +1,49 @@
|
|
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=Z0Www576hBMSCnvQEEiEW78Kzeh3-To2S6xhHM-p7z8,27970
|
42
|
+
lgt_jobs/lgt_data/mongo_repository.py,sha256=GpYqa9V24zFB78mFW6RfB2sRWidijzYUhyIhLK6Gf_c,37419
|
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.416.0.dist-info/METADATA,sha256=bV5A7ljvZqbyI5gN_aq1T_TIbFgSe89iJPpVA8C_4bc,1296
|
47
|
+
leadguru_jobs-0.416.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
48
|
+
leadguru_jobs-0.416.0.dist-info/top_level.txt,sha256=rIuw1DqwbnZyeoarBSC-bYeGOhv9mZBs7_afl9q4_JI,9
|
49
|
+
leadguru_jobs-0.416.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 (UpdateExternalUserProfileJob, UpdateExternalUserProfileJobData)
|
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
|
+
"UpdateExternalUserProfileJob": UpdateExternalUserProfileJob,
|
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
|
+
UpdateExternalUserProfileJob,
|
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
|
+
UpdateExternalUserProfileJobData,
|
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_jobs.lgt_common.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 lgt_data.mongo_repository import UserLeadMongoRepository
|
3
|
+
from lgt_jobs.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.now(datetime.UTC) - 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 lgt_data.enums import SourceType
|
9
|
-
from lgt_data.model import DedicatedBotModel, Server, Channel, DiscordUser
|
10
|
-
from lgt_data.mongo_repository import DedicatedBotRepository, UserMongoRepository
|
5
|
+
from lgt_jobs.lgt_common.discord_client.discord_client import DiscordClient
|
6
|
+
from lgt_jobs.lgt_common.helpers import get_formatted_bot_name
|
7
|
+
from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient
|
8
|
+
from lgt_jobs.lgt_data.enums import SourceType
|
9
|
+
from lgt_jobs.lgt_data.model import DedicatedBotModel, Server, Channel, DiscordUser
|
10
|
+
from lgt_jobs.lgt_data.mongo_repository import DedicatedBotRepository, UserMongoRepository
|
11
11
|
from pydantic import BaseModel
|
12
|
-
from lgt_data.analytics import get_bots_aggregated_analytics
|
13
|
-
from
|
14
|
-
from
|
12
|
+
from lgt_jobs.lgt_data.analytics import get_bots_aggregated_analytics
|
13
|
+
from lgt_jobs.lgt_common.lgt_logging import log
|
14
|
+
from lgt_jobs.lgt_common.enums.slack_errors import SlackErrors
|
15
15
|
from ..basejobs import BaseBackgroundJob, BaseBackgroundJobData
|
16
16
|
|
17
17
|
"""
|
lgt_jobs/jobs/chat_history.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
import datetime
|
2
2
|
from abc import ABC
|
3
3
|
from typing import Optional, List
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from lgt_data.model import
|
7
|
-
from lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository, UserContactsRepository
|
4
|
+
from lgt_jobs.lgt_common.lgt_logging import log
|
5
|
+
from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient, SlackMessageConvertService
|
6
|
+
from lgt_jobs.lgt_data.model import ChatMessage, UserModel, UserContact, DedicatedBotModel
|
7
|
+
from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository, UserContactsRepository, \
|
8
|
+
ChatRepository
|
8
9
|
from pydantic import BaseModel
|
9
|
-
from
|
10
|
+
from lgt_jobs.lgt_data.enums import SourceType
|
11
|
+
from lgt_jobs.runner import BaseBackgroundJob, BaseBackgroundJobData, BackgroundJobRunner
|
10
12
|
from ..env import portal_url
|
11
|
-
from ..basejobs import BaseBackgroundJob, BaseBackgroundJobData
|
12
13
|
from ..smtp import SendMailJobData, SendMailJob
|
13
14
|
|
14
15
|
"""
|
@@ -27,72 +28,76 @@ class LoadChatHistoryJob(BaseBackgroundJob, ABC):
|
|
27
28
|
return LoadChatHistoryJobData
|
28
29
|
|
29
30
|
def exec(self, data: LoadChatHistoryJobData):
|
30
|
-
"""download chat history"""
|
31
31
|
user = UserMongoRepository().get(data.user_id)
|
32
|
-
|
33
|
-
if not
|
32
|
+
bots = DedicatedBotRepository().get_all(only_valid=True, user_id=user.id, source_type=SourceType.SLACK)
|
33
|
+
if not bots:
|
34
34
|
return
|
35
|
-
|
36
|
-
log.info(f"[LoadChatHistoryJob]: processing {len(contacts)} contacts for user: {user.email}")
|
37
35
|
last_message = None
|
38
36
|
last_message_contact = None
|
39
|
-
for
|
40
|
-
|
41
|
-
|
42
|
-
if not message:
|
37
|
+
for bot in bots:
|
38
|
+
contacts = UserContactsRepository().find(user.id, spam=False, source_id=bot.source.source_id)
|
39
|
+
if not contacts:
|
43
40
|
continue
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
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)
|
45
|
+
|
46
|
+
if not message:
|
47
|
+
continue
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
49
|
+
if not last_message:
|
50
|
+
last_message = message
|
51
|
+
last_message_contact = contact
|
52
|
+
|
53
|
+
if message.created_at > last_message.created_at and message.user == contact.sender_id:
|
54
|
+
last_message = message
|
55
|
+
last_message_contact = contact
|
52
56
|
|
53
57
|
has_to_be_notified = (not user.new_message_notified_at or
|
54
58
|
(last_message and last_message.created_at > user.new_message_notified_at))
|
55
59
|
|
56
60
|
if last_message and has_to_be_notified and last_message.user == last_message_contact.sender_id:
|
57
61
|
LoadChatHistoryJob._notify_about_new_messages(user, last_message_contact, data.template_path)
|
58
|
-
UserMongoRepository().set(data.user_id, new_message_notified_at=datetime.datetime.
|
62
|
+
UserMongoRepository().set(data.user_id, new_message_notified_at=datetime.datetime.now(datetime.UTC))
|
59
63
|
|
60
64
|
@staticmethod
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
def _get_new_messages(contact: UserContact, bot: DedicatedBotModel, slack_chat: List[ChatMessage]):
|
66
|
+
chat_repo = ChatRepository()
|
67
|
+
messages = chat_repo.get_list(sender_id=contact.sender_id, bot_id=bot.id)
|
68
|
+
new_messages = []
|
69
|
+
for message in slack_chat:
|
70
|
+
same_messages = [msg for msg in messages if msg.ts == message.ts]
|
71
|
+
if not same_messages:
|
72
|
+
new_messages.append(message)
|
73
|
+
return new_messages
|
67
74
|
|
68
75
|
@staticmethod
|
69
|
-
def _update_history(user: UserModel, contact: UserContact) -> Optional[
|
70
|
-
bot
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
if not history.get('messages'):
|
76
|
+
def _update_history(user: UserModel, contact: UserContact, bot: DedicatedBotModel) -> Optional[ChatMessage]:
|
77
|
+
if bot.type == SourceType.SLACK:
|
78
|
+
slack_client = SlackWebClient(bot.token, bot.cookies)
|
79
|
+
try:
|
80
|
+
chat_id = slack_client.im_open(contact.sender_id).get('channel', {}).get('id')
|
81
|
+
history = slack_client.chat_history(chat_id)
|
82
|
+
except Exception as ex:
|
83
|
+
log.error(f'[LoadChatHistoryJob]: Failed to load chat for the contact: {contact.id}. ERROR: {str(ex)}')
|
78
84
|
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
|
82
85
|
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
86
|
+
if not history['ok']:
|
87
|
+
log.error(f'Failed to load chat for the contact: {contact.id}. ERROR: {history.get("error", "")}')
|
88
|
+
return
|
93
89
|
|
94
|
-
|
95
|
-
|
90
|
+
messages = history.get('messages', [])
|
91
|
+
if not messages:
|
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
|
96
101
|
|
97
102
|
@staticmethod
|
98
103
|
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 lgt_data.enums import DefaultBoards
|
5
|
-
from lgt_data.model import UserModel, DedicatedBotModel, SlackMemberInformation, UserLeadModel
|
6
|
-
from lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository, \
|
2
|
+
from lgt_jobs.lgt_common.lgt_logging import log
|
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
|
6
|
+
from lgt_jobs.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,7 +80,6 @@ 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,
|
84
83
|
dedicated_bot.source)
|
85
84
|
SlackContactUserRepository().collection().update_one({"sender_id": member_info.sender_id,
|
86
85
|
"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 lgt_data.mongo_repository import DedicatedBotRepository
|
5
|
+
from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient
|
6
|
+
from lgt_jobs.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_jobs.lgt_common.slack_client.web_client import SlackWebClient
|
5
5
|
from pydantic import BaseModel
|
6
6
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
7
7
|
|
@@ -1,10 +1,8 @@
|
|
1
|
-
import datetime
|
2
1
|
from abc import ABC
|
3
2
|
from typing import Optional
|
4
|
-
from
|
5
|
-
from
|
6
|
-
from lgt_data.mongo_repository import
|
7
|
-
DedicatedBotRepository, UserContactsRepository)
|
3
|
+
from lgt_jobs.lgt_common.lgt_logging import log
|
4
|
+
from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient
|
5
|
+
from lgt_jobs.lgt_data.mongo_repository import UserLeadMongoRepository, DedicatedBotRepository
|
8
6
|
from pydantic import BaseModel
|
9
7
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
10
8
|
|
@@ -27,7 +25,6 @@ class SendSlackMessageJob(BaseBackgroundJob, ABC):
|
|
27
25
|
|
28
26
|
def exec(self, data: SendSlackMessageJobData):
|
29
27
|
user_leads_repository = UserLeadMongoRepository()
|
30
|
-
user = UserMongoRepository().get(data.user_id)
|
31
28
|
lead = user_leads_repository.get_lead(user_id=data.user_id, lead_id=data.lead_id)
|
32
29
|
if not lead:
|
33
30
|
return
|
@@ -44,22 +41,6 @@ class SendSlackMessageJob(BaseBackgroundJob, ABC):
|
|
44
41
|
|
45
42
|
channel_id = resp['channel']['id']
|
46
43
|
if data.files_ids:
|
47
|
-
|
44
|
+
slack_client.share_files(data.files_ids, channel_id, data.text)
|
48
45
|
else:
|
49
|
-
|
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)
|
46
|
+
slack_client.post_message(channel_id, data.text)
|
@@ -1,34 +1,32 @@
|
|
1
1
|
from abc import ABC
|
2
|
-
from
|
3
|
-
from lgt_data.
|
4
|
-
from lgt_data.
|
2
|
+
from lgt_jobs.lgt_common.slack_client.slack_client import SlackClient
|
3
|
+
from lgt_jobs.lgt_data.enums import SourceType
|
4
|
+
from lgt_jobs.lgt_data.model import UserModel
|
5
|
+
from lgt_jobs.lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository
|
5
6
|
from pydantic import BaseModel
|
6
7
|
from ..basejobs import BaseBackgroundJobData, BaseBackgroundJob
|
7
8
|
|
8
|
-
"""
|
9
|
-
Update Slack User profile
|
10
|
-
"""
|
11
9
|
|
12
|
-
|
13
|
-
class UpdateUserSlackProfileJobData(BaseBackgroundJobData, BaseModel):
|
10
|
+
class UpdateExternalUserProfileJobData(BaseBackgroundJobData, BaseModel):
|
14
11
|
user_id: str
|
15
12
|
|
16
13
|
|
17
|
-
class
|
14
|
+
class UpdateExternalUserProfileJob(BaseBackgroundJob, ABC):
|
18
15
|
|
19
16
|
@property
|
20
17
|
def job_data_type(self) -> type:
|
21
|
-
return
|
18
|
+
return UpdateExternalUserProfileJobData
|
22
19
|
|
23
|
-
def exec(self, data:
|
20
|
+
def exec(self, data: UpdateExternalUserProfileJobData):
|
24
21
|
user = UserMongoRepository().get(data.user_id)
|
25
22
|
bots = DedicatedBotRepository().get_all(user_id=data.user_id, only_valid=True, include_deleted=False)
|
26
23
|
for bot in bots:
|
27
|
-
|
28
|
-
|
24
|
+
if bot.type == SourceType.SLACK:
|
25
|
+
slack = SlackClient(bot.token, bot.cookies)
|
26
|
+
UpdateExternalUserProfileJob.__update_slack_profile(user, slack)
|
29
27
|
|
30
28
|
@staticmethod
|
31
|
-
def
|
29
|
+
def __update_slack_profile(user: UserModel, slack: SlackClient):
|
32
30
|
profile = slack.get_team_profile()
|
33
31
|
title_section_id = None
|
34
32
|
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 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
|
4
|
+
from lgt_jobs.lgt_data.engine import UserCreditStatementDocument
|
5
|
+
from lgt_jobs.lgt_data.enums import UserAccountState, UserAction
|
6
|
+
from lgt_jobs.lgt_data.model import UserModel
|
7
|
+
from lgt_jobs.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.now(datetime.UTC),
|
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 lgt_data.enums import StatusConnection, SourceType
|
7
|
-
from lgt_data.model import UserWorkspace, SlackUser, DedicatedBotModel
|
8
|
-
from lgt_data.mongo_repository import UserMongoRepository, DedicatedBotRepository
|
4
|
+
from lgt_jobs.lgt_common.helpers import update_credentials, get_formatted_bot_name
|
5
|
+
from lgt_jobs.lgt_common.slack_client.web_client import SlackWebClient
|
6
|
+
from lgt_jobs.lgt_data.enums import StatusConnection, SourceType
|
7
|
+
from lgt_jobs.lgt_data.model import UserWorkspace, SlackUser, DedicatedBotModel
|
8
|
+
from lgt_jobs.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,4 +129,6 @@ 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
|
132
134
|
dedicated_bots_repository.add_or_update(dedicated_bot)
|
File without changes
|
File without changes
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import loguru
|
2
|
+
import requests
|
3
|
+
from requests import Response
|
4
|
+
from lgt_jobs.lgt_common.discord_client.methods import DiscordMethods
|
5
|
+
|
6
|
+
|
7
|
+
class DiscordClient:
|
8
|
+
base_url = 'https://discord.com/api/'
|
9
|
+
discord_api_version = 'v9/'
|
10
|
+
token: str
|
11
|
+
headers: dict
|
12
|
+
|
13
|
+
def __init__(self, token: str = None):
|
14
|
+
self.token = token
|
15
|
+
self.headers = {"Authorization": self.token}
|
16
|
+
|
17
|
+
def login(self, login: str, password: str, captcha_key: str = None) -> dict:
|
18
|
+
payload = {
|
19
|
+
'login': login,
|
20
|
+
'password': password,
|
21
|
+
'captcha_key': captcha_key,
|
22
|
+
"undelete": False,
|
23
|
+
"login_source": "",
|
24
|
+
"gift_code_sku_id": None
|
25
|
+
}
|
26
|
+
response = requests.post(f"{self.base_url}{self.discord_api_version}{DiscordMethods.LOGIN.value}", json=payload)
|
27
|
+
if response.status_code == 400 or response.status_code == 200:
|
28
|
+
return response.json()
|
29
|
+
return {}
|
30
|
+
|
31
|
+
def get_servers(self) -> list | dict:
|
32
|
+
response = requests.get(f"{self.base_url}{DiscordMethods.USER_GUILDS.value}", headers=self.headers)
|
33
|
+
return self.__response(response).json()
|
34
|
+
|
35
|
+
def get_dms(self) -> list | dict:
|
36
|
+
response = requests.get(f"{self.base_url}{DiscordMethods.USER_DMS.value}", headers=self.headers)
|
37
|
+
return self.__response(response).json()
|
38
|
+
|
39
|
+
def get_current_user(self) -> dict:
|
40
|
+
response = requests.get(f"{self.base_url}{DiscordMethods.USER.value}", headers=self.headers)
|
41
|
+
if response.status_code != 200:
|
42
|
+
self.__log_error(response)
|
43
|
+
return response.json()
|
44
|
+
|
45
|
+
def get_channels(self, guild_id: str) -> list | dict:
|
46
|
+
response = requests.get(f"{self.base_url}{DiscordMethods.guild_channels(guild_id)}", headers=self.headers)
|
47
|
+
return self.__response(response).json()
|
48
|
+
|
49
|
+
def get_invite_link(self, channel_id: str) -> Response:
|
50
|
+
response = requests.post(f'{self.base_url}{self.discord_api_version}'
|
51
|
+
f'{DiscordMethods.channels_invites(channel_id)}', headers=self.headers)
|
52
|
+
return self.__response(response)
|
53
|
+
|
54
|
+
@staticmethod
|
55
|
+
def __log_error(response: Response):
|
56
|
+
loguru.logger.warning(f"[DiscordClient WARNING]: {response.url}, {response.status_code}, {response.content}")
|
57
|
+
|
58
|
+
@staticmethod
|
59
|
+
def __response(response: Response):
|
60
|
+
if response.status_code != 200:
|
61
|
+
DiscordClient.__log_error(response)
|
62
|
+
return response
|
@@ -0,0 +1,16 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
|
3
|
+
|
4
|
+
class DiscordMethods(str, Enum):
|
5
|
+
USER_GUILDS = 'users/@me/guilds'
|
6
|
+
USER_DMS = 'users/@me/channels'
|
7
|
+
USER = 'users/@me'
|
8
|
+
LOGIN = 'auth/login'
|
9
|
+
|
10
|
+
@staticmethod
|
11
|
+
def guild_channels(guild_id: str):
|
12
|
+
return f'guilds/{guild_id}/channels'
|
13
|
+
|
14
|
+
@staticmethod
|
15
|
+
def channels_invites(channel_id: str):
|
16
|
+
return f'channels/{channel_id}/invites'
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import re
|
2
|
+
|
3
|
+
|
4
|
+
def update_credentials(credentials, token, cookies):
|
5
|
+
credentials.token = token
|
6
|
+
credentials.cookies = cookies
|
7
|
+
credentials.invalid_creds = False
|
8
|
+
return credentials
|
9
|
+
|
10
|
+
|
11
|
+
def get_formatted_bot_name(name):
|
12
|
+
bot_name = name
|
13
|
+
bot_name.replace(" ", "_") \
|
14
|
+
.replace(".", "dot_") \
|
15
|
+
.replace("#", "") \
|
16
|
+
.replace("+", "_plus")
|
17
|
+
|
18
|
+
return re.sub(r'[^A-Za-z0-9]', "", bot_name).lower()
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import sys
|
2
|
+
from loguru import logger as log
|
3
|
+
|
4
|
+
log.remove()
|
5
|
+
log.add(sys.stdout, format="{time} {name} {level} {message}", level="INFO",
|
6
|
+
filter=lambda record: record['level'] == 'INFO')
|
7
|
+
log.add(sys.stderr, format="{time} {name} {level} {message}", level="WARNING",
|
8
|
+
filter=lambda record: record['level'] == 'WARNING')
|
9
|
+
log.add(sys.stderr, format="{time} {name} {level} {message}", level="ERROR",
|
10
|
+
filter=lambda record: record['level'] in ['ERROR', 'FATAL', 'CRITICAL'])
|
11
|
+
|
12
|
+
|
13
|
+
log.info('Logger has been configured')
|
14
|
+
|
15
|
+
log = log
|