PHP code example of atendwa / nativephp-sms-reader
1. Go to this page and download the library: Download atendwa/nativephp-sms-reader library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
atendwa / nativephp-sms-reader example snippets
public function plugins(): array
{
return [
\Atendwa\SmsReader\SmsReaderServiceProvider::class,
];
}
use Atendwa\SmsReader\Facades\SmsReader;
public function debugSms(): void
{
$raw = SmsReader::getRawResponse(['sender' => 'MPESA', 'limit' => 1]);
dd($raw); // inspect the raw JSON from the native bridge
}
use Atendwa\SmsReader\Facades\SmsReader;
// All messages from MPESA in the last 30 days
$sinceMs = now()->subDays(30)->timestamp * 1000;
$messages = SmsReader::getMessages([
'sender' => 'MPESA',
'limit' => 500,
'since' => $sinceMs,
]);
// Each message: ['id' => string, 'sender' => string, 'body' => string, 'timestamp' => int]
foreach ($messages as $sms) {
echo $sms['body'];
}
use Atendwa\SmsReader\Events\SmsReceived;
use Native\Mobile\Attributes\OnNative;
class Dashboard extends Component
{
#[OnNative(SmsReceived::class)]
public function onSmsReceived(
string $sender,
string $body,
int $timestamp,
string $id,
): void {
// $sender — originating address, e.g. "MPESA"
// $body — full SMS text
// $timestamp — Unix milliseconds since epoch
// $id — "{sender}_{timestamp}", stable per message
}
}
use RuntimeException;
try {
$messages = SmsReader::getMessages(['sender' => 'MPESA']);
} catch (RuntimeException $e) {
// surface the error to the user
$this->error = $e->getMessage();
}
bash
php artisan native:run android
bash
php artisan native:plugin:list
bash
php artisan native:plugin:validate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.