sending-network/sdn-php-sdk

PHP SDK for interacting with Sending-Network

v0.2.0 2023-08-21 11:32 UTC

This package is not auto-updated.

Last update: 2024-04-29 15:02:59 UTC


README

Software License Software Version Software License

A PHP SDK for Sending-Network.

Installation

composer require sending-network/sdn-php-sdk

Usage

Prepare a configuration file

Provide server node url, wallet address, private key and developer key in file bot.creds.json:

{
    "nodeUrl": "https://example.com",
    "walletAddress": "<WALLET_ADDRESS>",
    "privateKey": "<PRIVATE_KEY>",
    "developerKey": "<DEVELOPER_KEY>"
}

Create an instance of SDNClient

require('vendor/autoload.php');
use SdnSdk\SDNClient;

$json_data = file_get_contents("bot.creds.json");
$config = json_decode($json_data,true);
$client = new SDNClient($config['nodeUrl']);

// login
$token = $client->login($config['walletAddress'], $config['privateKey'], $config['developerKey']);

// add listener for events
$client->addListener(function ($event) {
    // process room event here
    print_r($event);
}, "m.room.message");

// start listen
$client->listenForever();

Call API functions

// create new room
$client->createRoom("room name");

// invite user
$client->getRoom($roomId)->inviteUser($userId);

// send message
$client->getRoom($roomId)->sendText("hello");

Examples

See more use cases in examples directory.

License

MIT License.