|
7 | 7 |
|
8 | 8 | # == Log Config ==
|
9 | 9 |
|
10 |
| -logger = logging.getLogger("Bot Config") |
| 10 | +logger = logging.getLogger(__name__) |
11 | 11 | logger.setLevel(logging.DEBUG)
|
12 | 12 |
|
13 | 13 | ch = logging.StreamHandler()
|
|
44 | 44 | admin_name = os.getenv("ROCKETCHAT_ADMIN_USERNAME", "admin")
|
45 | 45 | admin_password = os.getenv("ROCKETCHAT_ADMIN_PASSWORD", "admin")
|
46 | 46 |
|
47 |
| -rasa_url = os.getenv("RASA_URL", "http://bot:5005/webhooks/rocketchat/webhook") |
| 47 | +rasa_url = os.getenv("RASA_URL", "http://bot-rocket:5005/webhooks/rocketchat/webhook") |
48 | 48 | user_header = None
|
49 | 49 |
|
50 | 50 |
|
@@ -121,40 +121,6 @@ def create_bot_user():
|
121 | 121 | )
|
122 | 122 |
|
123 | 123 |
|
124 |
| -def create_livechat_agent(): |
125 |
| - response = api_post("livechat/users/agent", {"username": bot["username"]}) |
126 |
| - return response["user"]["_id"] |
127 |
| - |
128 |
| - |
129 |
| -def configure_livechat(): |
130 |
| - # Enable Livechat |
131 |
| - api_post("settings/Livechat_enabled", {"value": True}) |
132 |
| - |
133 |
| - # Disable show pre-registration form |
134 |
| - api_post("settings/Livechat_registration_form", {"value": False}) |
135 |
| - |
136 |
| - # Change Livechat Color |
137 |
| - api_post("settings/Livechat_title_color", {"value": "#039046", "editor": "color"}) |
138 |
| - |
139 |
| - # Change Livechat Title |
140 |
| - api_post("settings/Livechat_title", {"value": bot["name"]}) |
141 |
| - |
142 |
| - # Disable Livechat Email display |
143 |
| - api_post("settings/Livechat_show_agent_email", {"value": False}) |
144 |
| - |
145 |
| - # Disable file upload |
146 |
| - api_post("settings/Livechat_fileupload_enabled", {"value": False}) |
147 |
| - |
148 |
| - # Change Livechat Webhook URL |
149 |
| - api_post("settings/Livechat_webhookUrl", {"value": rasa_url}) |
150 |
| - |
151 |
| - # Activate Livechat Webhook Send Request on Visitor Message |
152 |
| - api_post("settings/Livechat_webhook_on_visitor_message", {"value": True}) |
153 |
| - |
154 |
| - # Activate Livechat Webhook Send Request on Agent Messages |
155 |
| - api_post("settings/Livechat_webhook_on_agent_message", {"value": True}) |
156 |
| - |
157 |
| - |
158 | 124 | def configure_webhooks():
|
159 | 125 | webooks = api_get("integrations.list")
|
160 | 126 |
|
@@ -192,61 +158,33 @@ def configure_rocketchat():
|
192 | 158 | api_post("settings/API_Enable_CORS", {"value": True})
|
193 | 159 |
|
194 | 160 |
|
195 |
| -def create_department(bot_agent_id): |
196 |
| - get_departments_url = host + "/api/v1/livechat/department" |
197 |
| - |
198 |
| - get_departments_response = requests.get(get_departments_url, headers=user_header) |
199 |
| - |
200 |
| - number_of_departments = len(get_departments_response.json()["departments"]) |
201 |
| - |
202 |
| - if number_of_departments == 0: |
203 |
| - api_post( |
204 |
| - "livechat/department", |
205 |
| - { |
206 |
| - "department": { |
207 |
| - "enabled": True, |
208 |
| - "showOnRegistration": True, |
209 |
| - "name": "department", |
210 |
| - "description": "default department", |
211 |
| - }, |
212 |
| - "agents": [ |
213 |
| - { |
214 |
| - "agentId": bot_agent_id, |
215 |
| - "username": bot["username"], |
216 |
| - "count": 0, |
217 |
| - "order": 0, |
218 |
| - } |
219 |
| - ], |
220 |
| - }, |
221 |
| - ) |
222 |
| - |
223 |
| - |
224 | 161 | if __name__ == "__main__":
|
225 | 162 | logger.info("===== Automatic env configuration =====")
|
226 | 163 |
|
227 |
| - try: |
228 |
| - user_header = get_authentication_token() |
229 |
| - except Exception: |
230 |
| - print("\n\n --------- Rocket Chat Unavailable! --------\n\n") |
| 164 | + rocket_available = False |
| 165 | + |
| 166 | + while not rocket_available: |
| 167 | + try: |
| 168 | + user_header = get_authentication_token() |
| 169 | + rocket_available = True |
| 170 | + except Exception: |
| 171 | + import time |
| 172 | + logger.info("\n\n --------- Rocket Chat Unavailable! --------\n\n") |
| 173 | + logger.info(">> Waiting for 3 seconds...") |
| 174 | + time.sleep(3) |
| 175 | + |
| 176 | + logger.info(">> Connected to Rocket Instance") |
231 | 177 |
|
232 | 178 | if user_header:
|
233 | 179 | logger.info(">> Create user")
|
234 | 180 | create_bot_user()
|
235 | 181 |
|
236 |
| - logger.info(">> Create livechat agent") |
237 |
| - bot_agent_id = create_livechat_agent() |
238 |
| - |
239 |
| - logger.info(">> Configure livechat") |
240 |
| - configure_livechat() |
241 |
| - |
242 | 182 | logger.info(">> Configure Rocketchat")
|
243 | 183 | configure_rocketchat()
|
244 | 184 |
|
245 | 185 | logger.info(">> Configure Webhooks")
|
246 | 186 | configure_webhooks()
|
247 | 187 |
|
248 |
| - logger.info(">> Create livechat department") |
249 |
| - create_department(bot_agent_id) |
250 | 188 |
|
251 | 189 | else:
|
252 |
| - logger.error("Login Failed") |
| 190 | + logger.error(">> Login Failed") |
0 commit comments