- version: 1.0.1
- Last update: January 2020
- Environment: Windows
- Compiler: Python
- Prerequisite: Access to Messenger application
Refinitiv's Messenger application is a free to use, compliant and secure messaging platform. It is a powerful communication tool that provides desktop, mobile, and web access, and allows sharing messages, data, files, screenshots, and emoticons with your contacts.
The Messenger Bot API provides a set of available API calls to build automated workflows or bots for the Messenger application. The Bot API allows your applications to connect with and pass information into Eikon’s Messenger service programmatically or interact with a bot via a WebSocket connection.
- Overview
- Prerequisite
- Getting the AppKey value
- Setting the Messenger application
- Running the REST API demo application
- Running the WebSocket API demo application
- Running demo applications with debug log
- Authors
- References
This demo project shows how to implement the Messenger BOT API console applications with the REST and WebSocket APIs in Python programming language. The applications makes an authentication with RDP Authentication service, then lets developers interact with Messeger Application/Chatroom on behalf of Bot via the REST and WebSocket APIs.
- chatbot_demo_rest.py: A REST API example that sends chat message to individual and a Chatroom.
- chatbot_demo_ws.py: A REST and WebSocket APIs example that sends and receives chat message with a Chatroom.
- rdp_token.py: A Python module that manages RDP Authentication process for chatbot_demo_rest.py and chatbot_demo_ws.py applications. This module is based on RDP Python Quickstart Python source code implemented by Gurpreet Bal.
Note: Please note that the main concept for using Messager Bot REST and WebSocket APIs are the same for all technologies (see JavaScript example).
This tutorial source code requires the following dependencies.
- Messenger application.
- Python compiler and runtime
- Python's requests 2.x library for both REST and WebSocket connections.
- Python's websocket-client library (version 0.49 or greater) for the WebSocket connection .
- Messenger Bot API access and license.
Please contact your Refinitiv's representative and Dino Diviacchi ([email protected]) to help you to access Messenger application and Bot API. The Refinitiv team will then provision and set up the bot. Once this is done the email user you provided will receive an automated email with how to set up a password for the bot.
Note:
- The Python example has been qualified with Python versions 3.6.5
- Please refer to the pip installation guide page if your environment does not have the pip tool installed.
- If your environment already have a websocket-client library installed, you can use
pip list
command to verify a library version, then usepip install --upgrade websocket-client
command to upgrade websocket-client library.
Once you have setup your Messenger user, please access the AppKey Generator Tool via Eikon Desktop/Refinitiv Workspace application (go to the Search Bar and type APP KEY
, then select the AppKey Generator) or via a web site (Please access with your Eikon account, not your bot account).
You can generate your AppKey via the following steps:
- Enter an App Display Name
- Select the tick box next to EDP API as the API Type
- Click ‘Register’ New App button
You will then see a row for your new app with an AppKey item, which is your client_id for the Refinitiv Data Platform (RDP) Authentication.
Once you have setup your Messenger user and Bot user, you can add the Bot and create a Chatroom for you and your Bot via the following steps
-
Login to your personal Messenger to add the bot to your contacts, using “Add a New Contact” from the menu in the lower left corner.
-
Add bot name [email protected].
-
Once you have add the bot it will show up under your contacts (on the left side).
-
Create a chatroom using "Create a Bilateral chatroom" button from the menu in the lower left corner.
-
Add your Bot to a chatroom by dragging it into your newly created chatroom.
- Unzip or download the tutorial project folder into a directory of your choice
- Open a command prompt or console.
- Run
$>pip install -r rest-requirements.txt
command in a console to install all the dependencies libraries. - Open the chatbot_demo_rest.py demo application source code with your editor and input the following parameters
app_key
: Your AppKeybot_username
: Your Bot usernamebot_password
: Your Bot passwordrecipient_email
: Your assoicate Messenger email address
- OOpen a command prompt and go to folder src, then run the demo application with the following command.
$>python chatbot_demo_rest.py
- The application then authenticates with RDP Authentication service and sends a 1-1 message to your assoicate Eikon message email address.
Getting RDP Authentication Token Saving Authentication information to file Successfully Authenticated send 1 to 1 message to <email> Messenger BOT API: post a 1 to 1 message to <email> success
- Then a demo gets an associate Chatroom and joining to that Chatroom.
Get Rooms Messenger BOT API: get chatroom success Join Rooms Messenger BOT API: join chatroom success
- The demo application will send a default
Hello from Python
message to a Chatroom on behalf of the Bot API and lets you send your own message before leaving a Chatroom.sending message to {...} Rooms Messenger BOT API: post message to chatroom success Please input your message: Wendy, I'm home. Messenger BOT API: post message to chatroom success Leave Rooms Messenger BOT API: leave chatroom success
- Unzip or download the tutorial project folder into a directory of your choice.
- Open a command prompt or console.
- Run
$>pip install -r ws-requirements.txt
command in a console to install all the dependencies libraries. - Open the chatbot_demo_ws.py demo application source code with your editor and input the following parameters
app_key
: Your AppKeybot_username
: Your Bot usernamebot_password
: Your Bot passwordrecipient_email
: Your assoicate Messenger email address (For 1 to 1 message)
- Open a command prompt and go to folder src, then run the demo application with the following command.
$>python chatbot_demo_ws.py
- The demo will perform authentication process, get an assoicate chatroom, then join that chatroom as same as the REST API demo application above
- Then demo connects to the Messenger BOT API WebSocket server. Once the application shows WebSocket
connected
event in a console, you can start interact with your bot via a chatroom.Messenger BOT API: join chatroom success Connecting to WebSocket wss://api.collab.refinitiv.com/services/nt/api/messenger/v1/stream ... WebSocket Connection is established Sent:.... Received: { "event":"connected", "reqId":"943378" }
- Now we should be able to receive a response from our chatbot. You can test by sending
hello
message in to a Chatroom to see an example. - The Messenger application supports tabular data, hyperlinks and a full set of emoji in the message. You can type
/complex_message
message into a Chatroom to see an example.
You can enable the REST and WebSocket application debug log level via log_level = logging.WARN
application source code statement.The supported values are logging.WARN and logging.DEBUG levels.
The logging.DEBUG level shows incoming and outgoing messages between the demo applications and Messenger BOT API REST and WebSocket servers.
- Wasin Waeosri ([email protected])
- Dino Diviacchi ([email protected])
For further details, please check out the following resources: