Update app.py
Browse files
app.py
CHANGED
@@ -20,31 +20,32 @@ logger = logging.getLogger(__name__)
|
|
20 |
# Initialize Flask app
|
21 |
app = Flask(__name__)
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
"chat_id": TELEGRAM_CHAT_ID,
|
33 |
-
"text": text,
|
34 |
-
"parse_mode": "HTML"
|
35 |
}
|
36 |
-
|
37 |
-
|
38 |
-
"
|
39 |
-
"parse_mode": "HTML"
|
40 |
}
|
|
|
41 |
try:
|
42 |
-
response = requests.post(
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
except Exception as e:
|
46 |
-
logger.error(f"
|
47 |
-
return {"
|
48 |
|
49 |
def send_to_api(pair_name, message):
|
50 |
"""Send the message to the external API."""
|
@@ -204,12 +205,12 @@ def check_and_process_signals():
|
|
204 |
close_signal = False
|
205 |
|
206 |
for pair, message_data in all_messages.items():
|
207 |
-
# Send to Telegram
|
208 |
-
|
209 |
-
if
|
210 |
-
logger.info(f"
|
211 |
else:
|
212 |
-
logger.error(f"Failed to send
|
213 |
|
214 |
# Handle based on message type
|
215 |
if message_data["type"] == "regular":
|
@@ -233,12 +234,12 @@ def check_and_process_signals():
|
|
233 |
message_data = extract_message_content(analysis, main_pair)
|
234 |
|
235 |
if message_data:
|
236 |
-
# Send to Telegram
|
237 |
-
|
238 |
-
if
|
239 |
-
logger.info(f"
|
240 |
else:
|
241 |
-
logger.error(f"Failed to send
|
242 |
|
243 |
# Handle based on message type
|
244 |
if message_data["type"] == "regular":
|
|
|
20 |
# Initialize Flask app
|
21 |
app = Flask(__name__)
|
22 |
|
23 |
+
# Message API configuration
|
24 |
+
MESSAGE_API_URL = "https://aoamrnuwara.pythonanywhere.com/api/send-message"
|
25 |
+
MESSAGE_API_KEY = "Seakp0683asppoit"
|
26 |
+
|
27 |
+
def send_message_to_api(message):
|
28 |
+
"""Send a message via the message forwarding API."""
|
29 |
+
headers = {
|
30 |
+
"Content-Type": "application/json",
|
31 |
+
"X-API-Key": MESSAGE_API_KEY
|
|
|
|
|
|
|
32 |
}
|
33 |
+
|
34 |
+
payload = {
|
35 |
+
"message": message
|
|
|
36 |
}
|
37 |
+
|
38 |
try:
|
39 |
+
response = requests.post(MESSAGE_API_URL, headers=headers, data=json.dumps(payload))
|
40 |
+
response.raise_for_status()
|
41 |
+
logger.info(f"Message sent to API successfully. Status Code: {response.status_code}")
|
42 |
+
return {"success": True, "response": response.json()}
|
43 |
+
except requests.exceptions.RequestException as e:
|
44 |
+
logger.error(f"API request error: {e}")
|
45 |
+
return {"success": False, "error": str(e)}
|
46 |
except Exception as e:
|
47 |
+
logger.error(f"Unexpected error sending message to API: {e}")
|
48 |
+
return {"success": False, "error": str(e)}
|
49 |
|
50 |
def send_to_api(pair_name, message):
|
51 |
"""Send the message to the external API."""
|
|
|
205 |
close_signal = False
|
206 |
|
207 |
for pair, message_data in all_messages.items():
|
208 |
+
# Send to messaging API instead of directly to Telegram
|
209 |
+
api_msg_result = send_message_to_api(message_data["full_message"])
|
210 |
+
if api_msg_result["success"]:
|
211 |
+
logger.info(f"Message sent via API for {pair}")
|
212 |
else:
|
213 |
+
logger.error(f"Failed to send message via API: {api_msg_result.get('error')}")
|
214 |
|
215 |
# Handle based on message type
|
216 |
if message_data["type"] == "regular":
|
|
|
234 |
message_data = extract_message_content(analysis, main_pair)
|
235 |
|
236 |
if message_data:
|
237 |
+
# Send to messaging API instead of directly to Telegram
|
238 |
+
api_msg_result = send_message_to_api(message_data["full_message"])
|
239 |
+
if api_msg_result["success"]:
|
240 |
+
logger.info(f"Message sent via API for {main_pair}")
|
241 |
else:
|
242 |
+
logger.error(f"Failed to send message via API: {api_msg_result.get('error')}")
|
243 |
|
244 |
# Handle based on message type
|
245 |
if message_data["type"] == "regular":
|