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.
Files changed (43) hide show
  1. {leadguru_jobs-0.414.0.dist-info → leadguru_jobs-0.415.0.dist-info}/METADATA +5 -10
  2. leadguru_jobs-0.415.0.dist-info/RECORD +26 -0
  3. lgt_jobs/__init__.py +4 -4
  4. lgt_jobs/jobs/analytics.py +1 -1
  5. lgt_jobs/jobs/archive_leads.py +2 -2
  6. lgt_jobs/jobs/bot_stats_update.py +9 -9
  7. lgt_jobs/jobs/chat_history.py +52 -57
  8. lgt_jobs/jobs/inbox_leads.py +6 -5
  9. lgt_jobs/jobs/mass_message.py +2 -2
  10. lgt_jobs/jobs/send_code.py +1 -1
  11. lgt_jobs/jobs/send_slack_message.py +24 -5
  12. lgt_jobs/jobs/update_slack_profile.py +14 -12
  13. lgt_jobs/jobs/user_balance_update.py +5 -5
  14. lgt_jobs/jobs/workspace_connect.py +5 -7
  15. lgt_jobs/main.py +11 -9
  16. lgt_jobs/runner.py +9 -6
  17. lgt_jobs/smtp.py +1 -1
  18. leadguru_jobs-0.414.0.dist-info/RECORD +0 -49
  19. lgt_jobs/lgt_common/__init__.py +0 -0
  20. lgt_jobs/lgt_common/discord_client/__init__.py +0 -0
  21. lgt_jobs/lgt_common/discord_client/discord_client.py +0 -62
  22. lgt_jobs/lgt_common/discord_client/methods.py +0 -16
  23. lgt_jobs/lgt_common/enums/__init__.py +0 -0
  24. lgt_jobs/lgt_common/enums/slack_errors.py +0 -6
  25. lgt_jobs/lgt_common/helpers.py +0 -18
  26. lgt_jobs/lgt_common/lgt_logging.py +0 -15
  27. lgt_jobs/lgt_common/pubsub/__init__.py +0 -0
  28. lgt_jobs/lgt_common/pubsub/command.py +0 -14
  29. lgt_jobs/lgt_common/pubsub/messages.py +0 -37
  30. lgt_jobs/lgt_common/pubsub/pubsubfactory.py +0 -51
  31. lgt_jobs/lgt_common/slack_client/__init__.py +0 -0
  32. lgt_jobs/lgt_common/slack_client/methods.py +0 -46
  33. lgt_jobs/lgt_common/slack_client/slack_client.py +0 -392
  34. lgt_jobs/lgt_common/slack_client/web_client.py +0 -167
  35. lgt_jobs/lgt_data/__init__.py +0 -0
  36. lgt_jobs/lgt_data/analytics.py +0 -723
  37. lgt_jobs/lgt_data/engine.py +0 -223
  38. lgt_jobs/lgt_data/enums.py +0 -68
  39. lgt_jobs/lgt_data/helpers.py +0 -2
  40. lgt_jobs/lgt_data/model.py +0 -956
  41. lgt_jobs/lgt_data/mongo_repository.py +0 -1015
  42. {leadguru_jobs-0.414.0.dist-info → leadguru_jobs-0.415.0.dist-info}/WHEEL +0 -0
  43. {leadguru_jobs-0.414.0.dist-info → leadguru_jobs-0.415.0.dist-info}/top_level.txt +0 -0
@@ -1,167 +0,0 @@
1
- import requests
2
- from google.cloud import storage
3
- from datetime import datetime, timedelta
4
- from lgt_jobs.lgt_data.model import ChatMessage
5
- from .slack_client import SlackClient
6
- from ...lgt_data.mongo_repository import to_object_id
7
-
8
-
9
- def get_file_url(blob_path):
10
- storage_client = storage.Client()
11
- bucket = storage_client.get_bucket(SlackFilesClient.bucket_name)
12
- blob = bucket.get_blob(blob_path)
13
- if not blob:
14
- return None
15
- # valid for 3 days
16
- return blob.generate_signed_url(timedelta(3))
17
-
18
-
19
- class SlackMessageConvertService:
20
- @staticmethod
21
- def from_slack_response(user_email, bot_name, bot_token, dic, sender_id, bot_id, user_id, cookies=None):
22
-
23
- """
24
- :rtype: SlackHistoryMessageModel
25
- """
26
- result = ChatMessage()
27
- result.sender_id = sender_id
28
- result.bot_id = bot_id
29
- result.text = dic.get('text', '')
30
- result.user = dic.get('user', '')
31
- result.ts = dic.get('ts', '')
32
- result.attachments = dic.get('attachments', [])
33
- result.files = []
34
- result.user_id = to_object_id(user_id)
35
-
36
- if 'files' in dic:
37
- for file in dic.get('files'):
38
- if file.get('mode', '') == "tombstone" or not file.get('url_private_download'):
39
- continue
40
- new_file = ChatMessage.SlackFileModel()
41
- new_file.id = file.get('id')
42
- new_file.name = file.get('name')
43
- new_file.title = file.get('title')
44
- new_file.filetype = file.get('filetype')
45
- new_file.size = file.get('size')
46
- new_file.mimetype = file.get('mimetype')
47
-
48
- url_private_download = file.get('url_private_download')
49
- new_file.download_url = SlackFilesClient.get_file_url(user_email, bot_name, bot_token,
50
- new_file.id, url_private_download,
51
- new_file.mimetype, cookies)
52
- result.files.append(new_file)
53
-
54
- js_ticks = int(result.ts.split('.')[0] + result.ts.split('.')[1][3:])
55
- result.created_at = datetime.fromtimestamp(js_ticks / 1000.0)
56
- return result
57
-
58
-
59
- class SlackFilesClient:
60
- bucket_name = 'lgt_service_file'
61
-
62
- # Consider to cache these file somewhere in the super-fast cache solution
63
- @staticmethod
64
- def get_file_url(user_email, bot_name, bot_token, file_id, url_private_download, mimetype, cookies=None):
65
- storage_client = storage.Client()
66
- bucket = storage_client.get_bucket(SlackFilesClient.bucket_name)
67
- blob_path = f'slack_files/{user_email}/{bot_name}/{file_id}'
68
- blob = bucket.get_blob(blob_path)
69
-
70
- if not blob:
71
- res = requests.get(url_private_download, headers={'Authorization': f'Bearer {bot_token}'}, cookies=cookies)
72
- if res.status_code != 200:
73
- raise Exception(
74
- f'Failed to download file: {url_private_download} from slack due to response: '
75
- f'Code: {res.status_code} Error: {res.content}')
76
- blob = bucket.blob(blob_path)
77
- blob.upload_from_string(res.content, content_type=mimetype)
78
-
79
- blob = bucket.get_blob(blob_path)
80
- # valid for 3 days
81
- return blob.generate_signed_url(timedelta(3))
82
-
83
-
84
- class SlackWebClient:
85
- def __init__(self, token, cookies=None):
86
- if isinstance(cookies, list):
87
- cookies = {c['name']: c['value'] for c in cookies}
88
-
89
- self.client = SlackClient(token, cookies)
90
-
91
- def delete_message(self, channel: str, ts: str):
92
- return self.client.delete_message(channel, ts)
93
-
94
- def update_message(self, channel: str, ts: str, text: str, file_ids=''):
95
- return self.client.update_message(channel, ts, text, file_ids)
96
-
97
- def get_profile(self, user_id):
98
- return self.client.user_info(user_id)
99
-
100
- def get_im_list(self):
101
- return self.client.get_im_list()
102
-
103
- def chat_history(self, channel):
104
- return self.client.conversations_history(channel)
105
-
106
- def post_message(self, to, text):
107
- return self.client.post_message(to, text)
108
-
109
- def user_list(self):
110
- return self.client.users_list()
111
-
112
- def channels_list(self):
113
- return self.client.get_conversations_list()
114
-
115
- def im_open(self, sender_id):
116
- return self.client.im_open(sender_id)
117
-
118
- def update_profile(self, profile):
119
- return self.client.update_profile(profile)
120
-
121
- def channel_join(self, channels):
122
- return self.client.join_channels(channels)
123
-
124
- def channel_leave(self, channels):
125
- return self.client.leave_channels(channels)
126
-
127
- def get_reactions(self, channel, ts):
128
- return self.client.get_reactions(channel, ts)
129
-
130
- def upload_file(self, file, file_name):
131
- return self.client.upload_file(file, file_name)
132
-
133
- def download_file(self, file_url):
134
- return self.client.download_file(file_url)
135
-
136
- def delete_file(self, file_id):
137
- return self.client.delete_file(file_id)
138
-
139
- def share_files(self, files_ids: list, channel: str, text: str = None) -> dict:
140
- return self.client.share_files(files_ids, channel, text)
141
-
142
- def check_email(self, email: str, user_agent: str) -> bool:
143
- return self.client.check_email(email, user_agent)
144
-
145
- def confirm_email(self, email: str, user_agent: str, locale: str = 'en-US') -> bool:
146
- return self.client.confirm_email(email, user_agent, locale)
147
-
148
- def confirm_code(self, email: str, code: str, user_agent: str, ) -> requests.Response:
149
- return self.client.confirm_code(email, code, user_agent)
150
-
151
- def find_workspaces(self, user_agent: str, ) -> requests.Response:
152
- return self.client.find_workspaces(user_agent)
153
-
154
- def conversation_replies(self, channel: str, ts: str) -> dict:
155
- return self.client.conversations_replies(channel, ts)
156
-
157
- def create_shared_invite(self):
158
- return self.client.create_shared_invite()
159
-
160
- def send_slack_invite_to_workspace(self, email: str):
161
- return self.client.send_slack_invite_to_workspace(email=email)
162
-
163
- def test_auth(self):
164
- return self.client.test_auth()
165
-
166
- def get_team_info(self):
167
- return self.client.get_team_info()
File without changes