All Projects → artyom-poptsov → matrix-php

artyom-poptsov / matrix-php

Licence: GPL-3.0 license
PHP library for Matrix (https://matrix.org/) API.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to matrix-php

python
A Python 3 asyncio Matrix framework.
Stars: ✭ 115 (+576.47%)
Mutual labels:  matrix-org
Dendrite
Dendrite is a second-generation Matrix homeserver written in Go!
Stars: ✭ 2,758 (+16123.53%)
Mutual labels:  matrix-org
Matrix Docker Ansible Deploy
Matrix (An open network for secure, decentralized communication) server setup using Ansible and Docker
Stars: ✭ 2,541 (+14847.06%)
Mutual labels:  matrix-org
Synapse
Synapse: Matrix homeserver written in Python 3/Twisted.
Stars: ✭ 8,733 (+51270.59%)
Mutual labels:  matrix-org
matrix-corporal
Matrix Corporal: reconciliator and gateway for a managed Matrix server
Stars: ✭ 100 (+488.24%)
Mutual labels:  matrix-org
rust-synapse-compress-state
A tool to compress some state in a Synapse instance's database
Stars: ✭ 69 (+305.88%)
Mutual labels:  matrix-org
go
A Golang Matrix framework.
Stars: ✭ 192 (+1029.41%)
Mutual labels:  matrix-org
AgentSmith
🕴 An IRC server that is actually a Matrix client. Use your favourite IRC client to communicate with the Matrix.
Stars: ✭ 35 (+105.88%)
Mutual labels:  matrix-org
matrix-registration
a token based matrix registration api
Stars: ✭ 182 (+970.59%)
Mutual labels:  matrix-org
instagram
A Matrix-Instagram DM puppeting bridge
Stars: ✭ 69 (+305.88%)
Mutual labels:  matrix-org
transform
No description or website provided.
Stars: ✭ 13 (-23.53%)
Mutual labels:  matrix-org
matrix-pstn-bridge
☎️ A Matrix Puppet bridge for the public telephone network that supports a number of VoIP providers (Twillo, Vonage, etc.). Sends and receives voice and SMS.
Stars: ✭ 25 (+47.06%)
Mutual labels:  matrix-org
matrix-utils
Random matrix-related scripts.
Stars: ✭ 23 (+35.29%)
Mutual labels:  matrix-org
twitter
A Matrix-Twitter DM puppeting bridge
Stars: ✭ 48 (+182.35%)
Mutual labels:  matrix-org
signaller
The lightweight (but full-featured) Matrix server, written in Go language
Stars: ✭ 44 (+158.82%)
Mutual labels:  matrix-org
chooj
Matrix chat app for KaiOS supporting voice calls
Stars: ✭ 44 (+158.82%)
Mutual labels:  matrix-org
telegram
A Matrix-Telegram hybrid puppeting/relaybot bridge
Stars: ✭ 914 (+5276.47%)
Mutual labels:  matrix-org

Matrix-PHP

A simple library that allows to interact with a Matrix instance through the API.

PHP Composer

License

Matrix-PHP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Please see LICENSE file for the terms of GNU General Public License.

Dependencies

  • curl

Installation

Manually (on Ubuntu)

$ sudo apt install php-curl
$ git clone https://github.com/artyom-poptsov/matrix-php.git

By Composer

Create composer.json in your project directory (or add dependencies to it):

{
    "require": {
        "artyom-poptsov/matrix-php": "dev-master"
    },
    "repositories": [
        {
            "type":  "git",
            "url":   "https://github.com/artyom-poptsov/matrix-php"
        }
    ]
}

Then execute:

$ composer install

Syncing with the upstream

$ composer update

Testing

$ composer run-script test

Generating API documentation

$ composer run-script doc

The documentation will be stored in doc directory.

Examples

Account creation

require_once('vendor/artyom-poptsov/matrix-php/matrix/Matrix.php');

use \matrix\Matrix;

$m = new Matrix('https://example.org:8448', 'secret-token');

// 'true' means that the created user will be granted admin rights.
try {
    $m->request_registration('alice', 'passw0rd', true);
} catch (\matrix\Matrix_exception $e) {
    if ($e->get_errcode() == 'M_USER_IN_USE') {
        // Handle specific error.
    }
    // Do something else.
}

Login to the server

require_once('vendor/artyom-poptsov/matrix-php/matrix/Matrix.php');

use \matrix\Matrix;

$m = new Matrix('https://example.org:8448', 'secret-token');

$auth_methods = $m->get_available_login_methods();

// Only 'm.login.password' currently supported.
$session = $m->login('m.login.password', 'alice, 'passw0rd');

Please note that you should explicitly call logout method in order to finish the session:

$session->logout();

Calling to the logout method invalidates the session.

Change your password, if you wish

$result = $session->change_password('passw0rd', 'passw1rd');

Create a room (using existing session)

$room = false;
try {
    $room = $session->create_room("test");
} catch (Matrix_exception $e) {
    if ($e->get_errcode() == "M_ROOM_IN_USE") {
        // Handle specific error.
    }
    // Do something else.
}

Send a message to a room

$session = $m->login('m.login.password', 'alice, 'passw0rd');
$room = new Room('#test:example.org:8448, '!room-id:example.org:8448');
$event_id = $session->send_message($room, 'm.text', "hello");

Get admin rights

require_once('vendor/artyom-poptsov/matrix-php/matrix/Matrix.php');

use \matrix\Matrix;

$m       = new Matrix('https://example.org:8448', 'secret-token');
$session = $m->login('m.login.password', 'alice, 'passw0rd');

// This method call may fail if 'alice' has insufficient rights
//   ("This incident will be reported", you know):
$admin_session = $session->sudo();

Do your admin stuff

// 'make_fqn' method produces a Fully Qualified Name for the current Matrix server.
// For example: '@alice:example.org':
$fqn = $matrix->make_fqn('alice');

// 'false' here means that the user for whom the password was reset should NOT be
// logged out from all their devices (this is 'true' by default):
$admin_session->reset_password($fqn, 'new_password', false);

Deactivate an account

$fqn = $matrix->make_fqn('alice');
$admin_session->deactivate_account($fqn);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].