{"id":21092362,"url":"https://github.com/dfuchss/matrix-bot-base","last_synced_at":"2026-02-03T01:21:38.145Z","repository":{"id":193100919,"uuid":"687725976","full_name":"dfuchss/matrix-bot-base","owner":"dfuchss","description":"Base code for building matrix bots","archived":false,"fork":false,"pushed_at":"2026-01-29T17:54:19.000Z","size":262,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-30T05:25:03.336Z","etag":null,"topics":["bot","kotlin","matrix","trixnity"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dfuchss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-09-05T22:00:59.000Z","updated_at":"2026-01-29T17:53:55.000Z","dependencies_parsed_at":"2023-10-11T12:45:46.068Z","dependency_job_id":"b8309724-cd4c-4606-894c-8e4e9aedd89e","html_url":"https://github.com/dfuchss/matrix-bot-base","commit_stats":null,"previous_names":["dfuchss/matrix-bot-base"],"tags_count":63,"template":false,"template_full_name":null,"purl":"pkg:github/dfuchss/matrix-bot-base","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfuchss%2Fmatrix-bot-base","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfuchss%2Fmatrix-bot-base/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfuchss%2Fmatrix-bot-base/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfuchss%2Fmatrix-bot-base/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfuchss","download_url":"https://codeload.github.com/dfuchss/matrix-bot-base/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfuchss%2Fmatrix-bot-base/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29025945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T00:53:18.321Z","status":"ssl_error","status_checked_at":"2026-02-03T00:51:45.186Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","kotlin","matrix","trixnity"],"created_at":"2024-11-19T21:53:41.314Z","updated_at":"2026-02-03T01:21:38.137Z","avatar_url":"https://github.com/dfuchss.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Matrix Bot Base\n\nThis repository contains an abstraction layer to build bots using [Trixnity](https://trixnity.gitlab.io/trixnity/).\n\nI'm typically online in the [Trixnity channel](https://matrix.to/#/#trixnity:imbitbu.de). So feel free to tag me there if you have any questions.\n\n## Usage\n\nTo use this library, you need to add it as a dependency to your project. You can do this by adding the following to your `pom.xml`:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.fuchss\u003c/groupId\u003e\n    \u003cartifactId\u003ematrix-bot-base\u003c/artifactId\u003e\n    \u003cversion\u003eVERSION\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nThis library contains helper classes to build bots.\nStart by defining the creation of bot by creating a `Main.kt` file:\n\n```kotlin\nprivate lateinit var commands: List\u003cCommand\u003e\n\nfun main() {\n    Backend.set(DefaultBackend)\n    \n    runBlocking {\n        val config: IConfig = // Load config here \n            commands = listOf(HelpCommand(config, \"FancyBot\") { commands }, QuitCommand(), LogoutCommand(), ChangeUsernameCommand(), /* Custom commands here */)\n\n        val matrixClient = getMatrixClient(config)\n\n        val matrixBot = MatrixBot(matrixClient, config)\n        matrixBot.subscribeContent { event -\u003e handleCommand(commands, event, matrixBot, config) }\n        matrixBot.subscribeContent { encryptedEvent -\u003e handleEncryptedCommand(commands, encryptedEvent, matrixBot, config) }\n\n        val loggedOut = matrixBot.startBlocking()\n\n        // These lines will be reached if the bot shuts down\n        if (loggedOut) {\n            // Cleanup database stuff as you like (e.g., delete database files)\n            val databaseFiles = listOf(File(config.dataDirectory + \"/database.mv.db\"), File(config.dataDirectory + \"/database.trace.db\"))\n            databaseFiles.filter { it.exists() }.forEach { it.delete() }\n        }\n    }\n}\n\nprivate suspend fun getMatrixClient(config: Config): MatrixClient {\n    val existingMatrixClient = MatrixClient.create(\n        createRepositoriesModule(config),\n        createMediaStoreModule(config),\n        createCryptoDriverModule()\n    ).getOrNull()\n    if (existingMatrixClient != null) {\n        return existingMatrixClient\n    }\n\n    val matrixClient = MatrixClient.create(\n        createRepositoriesModule(config),\n        createMediaStoreModule(config),\n        createCryptoDriverModule(),\n        MatrixClientAuthProviderData.classicLogin(\n            baseUrl = Url(config.baseUrl),\n            identifier = IdentifierType.User(config.username),\n            password = config.password,\n            initialDeviceDisplayName = \"An interesting bot\"\n        ).getOrThrow()\n    ).getOrThrow()\n\n    return matrixClient\n}\n```\n\nYou also need a suitable configuration for your bot. You may use a class like this:\n\n```kotlin\n/**\n * This is the configuration template of the mensa bot.\n * @param[prefix] the command prefix the bot listens to. By default, \"bot\"\n * @param[baseUrl] the base url of the matrix server the bot shall use\n * @param[username] the username of the bot's account\n * @param[password] the password of the bot's account\n * @param[dataDirectory] the path to the databases and media folder\n * @param[admins] the matrix ids of the admins. E.g. \"@user:invalid.domain\"\n * @param[users] the matrix ids of the authorized users or servers. E.g. \"@user:invalid.domain\" or \":invalid.domain\"\n */\ndata class Config(\n    @JsonProperty override val prefix: String = \"bot\",\n    @JsonProperty override val baseUrl: String,\n    @JsonProperty override val username: String,\n    @JsonProperty override val password: String,\n    @JsonProperty override val dataDirectory: String,\n    @JsonProperty override val admins: List\u003cString\u003e,\n    @JsonProperty override val users: List\u003cString\u003e,\n) : IConfig {\n    companion object {\n        private val log: Logger = LoggerFactory.getLogger(Config::class.java)\n\n        /**\n         * Load the config from the file path. You can set \"CONFIG_PATH\" in the environment to override the default location (\"./config.json\").\n         */\n        fun load(): Config {\n            val configPath = System.getenv(\"CONFIG_PATH\") ?: \"./config.json\"\n            val configFile = File(configPath)\n            if (!configFile.exists()) {\n                error(\"Config ${configFile.absolutePath} does not exist!\")\n            }\n\n            val config: Config = ObjectMapper().registerKotlinModule().readValue(configFile)\n            log.info(\"Loaded config ${configFile.absolutePath}\")\n            config.validate()\n            return config\n        }\n    }\n}\n```\n\nThis creates a bot that can be used to handle text messages. The bot will automatically handle the following commands:\n\n* `help` - Shows a list of all available commands\n* `quit` - Quits the bot\n* `logout` - Quits the bot and logs out all sessions\n* `name {username}` - Changes the username of the bot\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfuchss%2Fmatrix-bot-base","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfuchss%2Fmatrix-bot-base","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfuchss%2Fmatrix-bot-base/lists"}