# 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

```php
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](/sending.network/sdk-documentation/developer-key.md).

### Prepare a configuration file

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

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sending-network.gitbook.io/sending.network/sdk-documentation/php-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
