Python API wrapper for Rocket.Chat
pip3 install rocketchat_API
python3 setup.py install
from pprint import pprint
from rocketchat_API.rocketchat import RocketChat
proxy_dict = {
"http" : "http://127.0.0.1:3128",
"https" : "https://127.0.0.1:3128",
}
rocket = RocketChat('user', 'pass', server_url='https://demo.rocket.chat', proxies=proxy_dict)
pprint(rocket.me().json())
pprint(rocket.channels_list().json())
pprint(rocket.chat_post_message('good news everyone!', channel='GENERAL', alias='Farnsworth').json())
pprint(rocket.channels_history('GENERAL', count=5).json())
note: every method returns a requests Response object.
If you are going to make a couple of request, you can user connection pooling provided by requests
. This will save significant time by avoiding re-negotiation of TLS (SSL) with the chat server on each call.
from requests import sessions
from pprint import pprint
from rocketchat_API.rocketchat import RocketChat
with sessions.Session() as session:
rocket = RocketChat('user', 'pass', server_url='https://demo.rocket.chat', session=session)
pprint(rocket.me().json())
pprint(rocket.channels_list().json())
pprint(rocket.chat_post_message('good news everyone!', channel='GENERAL', alias='Farnsworth').json())
pprint(rocket.channels_history('GENERAL', count=5).json())
from pprint import pprint
from rocketchat_API.rocketchat import RocketChat
rocket = RocketChat(user_id='WPXGmQ64S3BXdCRb6', auth_token='jvNyOYw2f0YKwtiFS06Fk21HBRBBuV7zI43HmkNzI_s', server_url='https://demo.rocket.chat')
pprint(rocket.me().json())
Only required parameters are explicit on the RocketChat class but you can still use all other parameters. For a detailed parameters list check the Rocket chat API
Most of the API methods are already implemented. If you are interested in a specific call just open an issue or open a pull request.
We are actively testing :)
Tests run on a Rocket.Chat Docker container so install Docker and docker-compose.
docker-compose up
and to take test server down docker-compose down
pytest
You can contribute by doing Pull Requests. (It may take a while to merge your code but if it's good it will be merged). Please, try to implement tests for all your code and use a PEP8 compliant code style.
Reporting bugs and asking for features is also contributing ;) Feel free to help us grow by registering issues.
We hang out here if you want to talk.
JetBrains supports this project by providing us with licenses for their fantastic products.