I am currently working on a project that requires extracting discussions from different group chats in Eikon Messenger using Python. To proceed, I need the following information and credentials:
Eikon Data API AppKey
Messenger Bot API credentials (bot_username, bot_password, messenger_appkey)
Additionally, I would appreciate it if you could provide the documentation or any guidelines on how to set up and use these APIs to extract the discussions.
Could you please help on this project?
Thank you for your support.
Best regards,
Ben
import eikon as ek
import requests
import websocket
import json
import threading
# Initialize Eikon Data API
ek.set_app_key('YOUR_EIKON_APPKEY')
# Messenger Bot API credentials
bot_username = 'your_bot_username'
bot_password = 'your_bot_password'
messenger_appkey = 'your_messenger_appkey'
messenger_ws_endpoint = 'wss://api.collab.refinitiv.com/services/nt/api/messenger/v1/stream'
# Authentication function
def authenticate():
url = 'https://api.refinitiv.com/auth/oauth2/v1/token'
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
data = {
'grant_type': 'client_credentials',
'client_id': messenger_appkey,
'client_secret': bot_password
}
response = requests.post(url, headers=headers, data=data)
return response.json()['access_token']
# WebSocket function to receive messages
def on_message(ws, message):
print(f"Received message: {message}")
def on_error(ws, error):
print(f"Error: {error}")
def on_close(ws, close_status_code, close_msg):
print("### closed ###")
def on_open(ws):
print("### opened ###")
# Main function to start the WebSocket connection
def start_websocket():
ws = websocket.WebSocketApp(messenger_ws_endpoint,
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever()
if __name__ == "__main__":
# Authenticate and get the access token
access_token = authenticate()
# Start the WebSocket connection to receive messages
websocket_thread = threading.Thread(target=start_websocket)
websocket_thread.start()