PHP SDK

This guide is designed to help you seamlessly integrate and interact with the SendingNetwork API using PHP. This documentation will walk you through the steps to set up, authenticate, and utilize the features of SendingNetwork to enable efficient and secure network communication within your PHP applications.

Installation

composer require sending-network/sdn-php-sdk

Usage

You will need a developer key to access the Edge Network. For further insight into the mechanism and to request a developer key, please consult the provided guide here.

Prepare a configuration file

In the file bot.creds.json, make sure to include the node URL, wallet address, private key, and developer key.

{
    "nodeUrl": "https://portal0101.sending.network",
    "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.

Last updated