This is a mostly auto-generated library for using the mattermost api from Dart.

Overview

Mattermost API Client in Dart

This is an implementation of a Mattermost API client in dart. It is not the only one, but it has significant advantages over others.

The other package called mattermost_dart depends on the dio library and therefore also on a number of others, but I think libraries should have the minimal number of dependencies possible, so this implementation depends only on the http library.

Additionally, there are incompatibilities between the openapi-generator-cli and the published mattermost swagger document. I have resolved many of those issues. See below.

Features

This library is a full implementation of the Mattermost Client API 4.0.0 in Dart.

Getting started

Install the package

dart pub add mattermost_api

Import the package in your Dart file

import 'package:mattermost_api/api.dart';

Creating a client

var mmClient = MattermostApiClient(
  basePath: '$mmBaseUrl/api/v4',
  authentication: MmHttpBearerAuthentication(config.mmToken),
);

Available authentication classes:

  • MmApiKeyAuthentication
  • MmHttpBasicAuthentication
  • MmHttpBearerAuthentication
  • MmOAuth

Accessing the API endpoints

There are many sub-apis available on Mattermost and they are exposed by getters on the MattermostApiClient object or may be created on their own.

Make your requests:

// using getters on the client instance
MmTeam? team = await mmClient.teams.getTeamByName(myTeamName);
MmChannel? channel = await mmClient.channels.getChannel(myChannelId);

// using the classes directly
var channelApi = MattermostChannelsApi(mmClient)
MmChannel? channel = await channelApi.getChannel(myChannelId);

Every API model in the library is prefixed with the word Mattermost and every object class is prefixed with the letters Mm so if you are using an IDE, simply start typing either Mattermost or Mm and your IDE should pick up everything that's available.

Using the Websocket Client for Real-time Updates

The library also exposes a simple wrapper around the Mattermost Websocket API for retrieving real-time updates. This is essential for bot accounts that need to reply to channel messages or direct messages.

Here's an example.

var token = 'BEARER_TOKEN';
var url = 'wss://BASE_URL/api/v4/websocket';
var ws = MattermostWebsocketClient(
  url,
  headers: {'Authorization': 'Bearer $token'},
  onEvent: (MmWsEvent mm) {
    if (mm is MmWsEventPosted) print('a user just posted a message!');
    print(mm.toJson());
  },
);

await Future.delayed(Duration(seconds: 2));
var res = await ws.userTyping('CHANNEL_ID_WHERE_USER_IS_TYPING');
print(res.toJson());
Future.delayed(Duration(seconds: 2));
res = await ws.getStatuses();
print(res.toJson());
await Future.delayed(Duration(seconds: 2));
res = await ws.getStatusesByIds(['USER_ID_TO_GET']);
print(res.toJson());

Note: the websocket API is significantly different from the REST API, and this library is still limited in its support. All events are supported through the MmWsEvent wrapper class, and as this library improves, we will add wrapper classes for the other events too.

Mattermost Websocket Documentation

More Details

Issues Resolved

mattermost swagger json schema errors

The mattermost swagger json document available here: https://api.mattermost.com/dcf9982f-0c24-4e65-8bcc-112a276758aa has some OpenAPI schema errors in it. I have fixed them and my version is located here in this repo as mattermost-swagger.json.

Additionally, the swagger document inconsistently capitalizes ldap in tags (endpoints). The code generator sees them as different apis, but we only want one, so I have modified the swagger document to make them all LDAP instead.

dart codegen problems

Additionally, when using the official openapi-generator-cli (version 6.0), the automatic Dart code generation has a few problems:

  • The underscore query variable allowed when retrieving a user's profile image resolves to a space character in the resulting Dart code and breaks compilation.
  • The generated code sometimes attempts to return objects of the wrong type.
  • The generated code fails to properly recognize empty OpenAPI object types as a Map<dynamic> and treats them as Object instead.
  • The generated code expects that we want the entire library to be automatically generated, and it creates a pubspec.yaml and everything. Since there are problems with the automatic code generation, it's better and safer to wrap the auto-generated code in a library we control.

I have resolved these problems by forking the openapi-generator-cli here to change the Dart code generator Java class and templates. Also, I have created my own build script (codegen.py) that does the following:

  • processes the swagger json using my custom build of openapi-generator-cli and my new templates (also in this repo under openapi_mattermost_templates).
  • makes a few additional replacements in the generated code
  • ignores the generated pubspec and instead copies the generated lib, test, and doc files into their final resting place.
You might also like...

Asset manager helps you auto-generate the assets code and add it to your pubspec.yaml .

Asset manager helps you auto-generate the assets code and add it to your pubspec.yaml .

Asset Manager Asset manager helps you auto-generate the assets code and add it to your pubspec.yaml . Quick start dart pub global activate asset_manag

Nov 1, 2022

This library provides the easiest and powerful Dart/Flutter library for Mastodon API 🎯

This library provides the easiest and powerful Dart/Flutter library for Mastodon API 🎯

The Easiest and Powerful Dart/Flutter Library for Mastodon API 🎯 1. Guide 🌎 1.1. Features 💎 1.2. Getting Started ⚡ 1.2.1. Install Library 1.2.2. Im

Jul 27, 2023

A most easily usable RESAS API wrapper in Dart. With this library, you can easily integrate your application with the RESAS API.

A most easily usable RESAS API wrapper library in Dart! 1. About 1.1. What Is RESAS? 1.2. Introduction 1.2.1. Install Library 1.2.2. Import It 1.2.3.

Apr 7, 2022

An Imgur API Client Library that uses Imgur's v3 API for Dart

An Imgur API Client Library that uses Imgur's v3 API for Dart

imgur.dart An Imgur API Client Library that uses Imgur's v3 API for Dart. Usage

Dec 2, 2022

Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight Node.js based Bhagavad Gita API [An open source rest api on indian Vedic Scripture Shrimad Bhagavad Gita].

Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight Node.js based Bhagavad Gita API [An open source rest api on indian Vedic Scripture Shrimad Bhagavad Gita].

Gita Bhagavad Gita flutter app. Download App - Playstore Web Application About Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight No

Apr 5, 2022

Beautiful Weather App using API with support for dark mode. Created by Jakub Sobański ( API ) and Martin Gogołowicz (UI, API help)

Beautiful Weather App using API with support for dark mode. Created by Jakub Sobański ( API ) and Martin Gogołowicz (UI, API help)

Flutter Weather App using API with darkmode support Flutter 2.8.1 Null Safety Beautiful Weather App using https://github.com/MonsieurZbanowanYY/Weathe

Nov 29, 2022

Flutter book library - Book Library Application with Flutter and Google Book API

Book Library Application Flutter iOS, Android and Web with Google Book API Demo

Jan 25, 2022

A most easily usable Duolingo API wrapper in Dart. Duolingo4D is an open-sourced Dart library.

A most easily usable Duolingo API wrapper in Dart! 1. About Duolingo4D Duolingo4D is an open-sourced Dart library. With Duolingo4D, you can easily int

Oct 17, 2022

A middleware library for Dart's http library.

http_middleware A middleware library for Dart http library. Getting Started http_middleware is a module that lets you build middleware for Dart's http

Oct 23, 2021
Owner
Also check out my repos over at: https://github.com/utopiantools
null
A Flutter mobile application built completely using DhiWise and Supabase without coding single line of code. With 100% system generated code

Flutter Expension Getting Started with Flutter ?? Generated with ❤️ from Dhiwise A Flutter mobile application built completely using DhiWise and Supab

DhiWise 11 Oct 23, 2022
Some UI mostly use when develop Flutter app

Demo Flutter - Some common UI in Flutter App include Hero Animation Screen - How to play with hero widget. Simple Animation Screen - Some simple anima

Duy Tran 57 Jul 24, 2022
(mostly) Automatic search-enabled appBar for flutter

flutter_search_bar A simple and mostly automatic material search bar for flutter (dart). Note: use flutter_search_bar and not search_bar -- I own both

Spencer 266 Dec 31, 2022
This is a expenses app which keeps a track of the money spend. Mostly helpful for college students like me...

expenses_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

null 2 Jun 5, 2022
SurrealDB client written in pure dart. auto reconnect, typed functions

SurrealDB Client For Dart & Flutter SurrealDB client for Dart and Flutter. Quick Start import 'package:surrealdb/surrealdb.dart'; void main(List<Stri

Duhan BALCI 10 Dec 18, 2022
An HTTP file downloader packed with many features -> resumable downloads, multiple connections, buffering, auto-retry, etc.

An HTTP file downloader packed with many features -> resumable downloads, multiple connections, buffering, auto-retry, etc. Features Resumable downloa

Liu YuanYuan 4 Feb 2, 2022
A customizable carousel slider widget in Flutter which supports inifinte scrolling, auto scrolling, custom child widget, custom animations and built-in indicators.

flutter_carousel_widget A customizable carousel slider widget in Flutter. Features Infinite Scroll Custom Child Widget Auto Play Horizontal and Vertic

NIKHIL RAJPUT 7 Nov 26, 2022
Demo app with continuous integration setup for auto across android/iOS app stores

demo_flutter_ci A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started

null 0 Dec 25, 2021
Auto route lib - Personal customized use to increase CupertinoRoute transition duration

Auto route lib - Personal customized use to increase CupertinoRoute transition duration , auto route 1.0.0-beta.10 base, so i have to reupload from .pub-cache instead fork it

Mochamad Nizwar Syafuan 0 Jan 4, 2022
Flutter plugin for auto resize widgets to get then "responsives".

Responsive Widgets This plugin helps to create responsive widgets, that makes auto-size with the proportion between reference screen size (width, heig

Lucas Henrique Polazzo 45 Nov 3, 2022