Skip to main content

Installation

pip install kchatdriver

Documentation

Documentation can be found at https://vaelor.github.io/python-mattermost-driver/ .

Usage

from kchatdriver import Driver

foo = Driver({
    """
    Required options

    """
    'url': 'myteam.kchat.infomaniak.com',
    'token': 'YourBotAccessToken',

    Be careful. This SHOULD NOT be active in production, because this logs a lot!
    Even the password for your account when doing driver.login()!
    """
    'debug': False
    """
})

"""
Most of the requests need you to be logged in, so calling login()
should be the first thing you do after you created your Driver instance.
login() returns the raw response.
If using a personal access token, you still need to run login().
In this case, does not make a login request, but a `get_user('me')`
and sets everything up in the client.
"""
foo.login()
foo.users.get_user_by_username('another.name')

"""
If the api request needs additional parameters
you can pass them to the function in the following way:
- Path parameters are always simple parameters you pass to the function
"""
foo.users.get_user(user_id='me')

# - Query parameters are always passed by passing a `params` dict to the function
foo.teams.get_teams(params={...})

# - Request Bodies are always passed by passing an `options` dict or array to the function
foo.channels.create_channel(options={...})

# See the mattermost api documentation to see which parameters you need to pass.
foo.channels.create_channel(options={
    'team_id': 'some_team_id',
    'name': 'awesome-channel',
    'display_name': 'awesome channel',
    'type': 'O'
})

"""
If you want to make a websocket connection to the kChat server
you can call the init_websocket method, passing an event_handler.
Every Websocket event send by kChat will be send to that event_handler.
See the API documentation for which events are available.
"""
foo.init_websocket(event_handler)

# Use `disconnect()` to disconnect the websocket
foo.disconnect()

# To upload a file you will need to pass a `files` dictionary
channel_id = foo.channels.get_channel_by_name_and_team_name('team', 'channel')['id']
file_id = foo.files.upload_file(
    channel_id=channel_id,
    files={'files': (filename, open(filename, 'rb'))}
)['file_infos'][0]['id']


# track the file id and pass it in `create_post` options, to attach the file
foo.posts.create_post(options={
    'channel_id': channel_id,
    'message': 'This is the important file',
    'file_ids': [file_id]})

# If needed, you can make custom requests by calling `make_request`
foo.client.make_request('post', '/endpoint', options=None, params=None, data=None, files=None, basepath=None)

# If you want to call a webhook/execute it use the `call_webhook` method.
# This method does not exist on the mattermost api AFAIK, I added it for ease of use.
foo.webhooks.call_webhook('myHookId', options) # Options are optional

Metadata

Release files for kchatdriver 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kchatdriver 0.1.1
File Size Uploaded
kchatdriver-0.1.1.tar.gz 26.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kchatdriver 0.1.1
File Interpreter ABI Platform
kchatdriver-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 57.1 kB

Release files / kchatdriver-0.1.1.tar.gz

Download URL kchatdriver-0.1.1.tar.gz
Size 26.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d76aec1781ec6e3f07a0bdb5a75e32212c9fb551e2e73d0bc086c37dfba08943
BLAKE2b-256 checksum
How to use checksums
89c229da1ca1d4f20e682dacac03fd1b87e29c543e9bbd70eb0945db5d700a18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / kchatdriver-0.1.1-py3-none-any.whl

Download URL kchatdriver-0.1.1-py3-none-any.whl
Size 30.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a1b8950db6a21fc43839f2027eb8b42d1f7d79af5932234d6e62554da1ee428
BLAKE2b-256 checksum
How to use checksums
7805b3766fc0bdda60ec806600c4a08d3b9fb4a546c15d109fdc1646b6c84c6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page