A PHP SDK for SendingNetwork. ## 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: ```json { "nodeUrl": "https://example.com", "walletAddress": "<WALLET_ADDRESS>", "privateKey": "<PRIVATE_KEY>", "developerKey": "<DEVELOPER_KEY>" } ``` ### Create an instance of `SDNClient` ```php 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 ```php // 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. ## SDNClient API ### Login DID ```php function login(string $walletAddress, string $privateKey, string $developerKey) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | walletAddress | string | user wallet address | true | | privateKey | string | account private key | true | | developerKey | string | developer key | true | output params: | Name | Type | Description | Required | | :------- | :---------- | :---------- | :------- | | access_token | string | access token | true | ### Create Room ```php function createRoom(string $name, bool $isPublic = false, array $invitees = []) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | name | string | room name | true | | isPublic | string | public or private | false | | invitees | string array | array of user ids to invite | false | output params: | Name | Type | Description | Required | | :------- | :---------- | :---------- | :------- | | room | Room | Room Object | true | ### Join Room ```php function joinRoom(string $roomIdOrAlias) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomIdOrAlias | string | room id or alias | true | output params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | room | Room | Room Object | true | ### Get Room Object ```php! function getRoom(string $roomId) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomId | string | room id | true | output params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | room | Room | Room Object | true | ## Room API ### Invite User ```php function inviteUser(string $userId) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | userId | string | user id | true | output params: none ### Kick User ```php function kickUser(string $userId) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | userId | string | user id | true | return values: none ### Leave Room ```php function leave() ``` input params:none output params: none ### Get Room Memebers ```php function getJoinedMembers() ``` input params:none output params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | roomMemberInfo | array of members | room member info | true | ### Send Message ```php function sendText(string $text) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | text | string | message to send | true | output params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | eventId | string | event id | true | ## User API ### Get Displayname ```php function getDisplayName() ``` input params:none output params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | displayname | string | user displayname | true | ### Set Displayname ```php function setDisplayName(string $displayName) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | displayname | string | user displayname | true | output params: none ### Get Avatar Url ```php function getAvatarUrl() ``` input params:none output params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | avatarUrl | string | user avatar url | true | ### Set Avatar Url ```php function setAvatarUrl(string $avatarUrl) ``` input params: | Name | Type | Description | Required | | :------ | :----- | :---------- | :------- | | avatarUrl | string | user avatar url | true | output params: none