Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Saifallak committed Dec 29, 2024
2 parents fbd1a37 + cc74dc9 commit 7cc8186
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/Cloudwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct()
{
$this->headers = [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . config('cloudwa.api_token'),
'Authorization' => 'Bearer '.config('cloudwa.api_token'),
'Accept' => 'application/json',
];

Expand Down Expand Up @@ -115,7 +115,7 @@ public function scheduleAt(?Carbon $scheduleAt): static

public function token(?string $apiToken): static
{
$this->headers['Authorization'] = 'Bearer ' . ($apiToken ?? config('cloudwa.api_token'));
$this->headers['Authorization'] = 'Bearer '.($apiToken ?? config('cloudwa.api_token'));

return $this;
}
Expand All @@ -141,7 +141,7 @@ public function sendMessage(): void
{
collect($this->phones)
->filter()
->map(fn($p) => $this->normalizeNumber($p))
->map(fn ($p) => $this->normalizeNumber($p))
->each(function ($phone) {

rescue(function () use ($phone) {
Expand Down Expand Up @@ -171,26 +171,26 @@ public function sendMessage(): void
public function checkAvailability(): bool
{
return collect($this->phones)
->filter()
->map(fn($p) => $this->normalizeNumber($p))
->map(function ($phone) {
return rescue(function () use ($phone) {
$res = Http::withHeaders($this->headers)
->timeout(5)
->throw()
->get('https://cloudwa.net/api/v2/sessions/check_availability', [
'session_uuid' => $this->sessionUuid ?? config('cloudwa.uuids.default'),
'chat_id' => $phone,
]);

info($res);

return ['status' => true];
}, function () {
return ['status' => false];
});

})->where('status', false)->count() == 0;
->filter()
->map(fn ($p) => $this->normalizeNumber($p))
->map(function ($phone) {
return rescue(function () use ($phone) {
$res = Http::withHeaders($this->headers)
->timeout(5)
->throw()
->get('https://cloudwa.net/api/v2/sessions/check_availability', [
'session_uuid' => $this->sessionUuid ?? config('cloudwa.uuids.default'),
'chat_id' => $phone,
]);

info($res);

return ['status' => true];
}, function () {
return ['status' => false];
});

})->where('status', false)->count() == 0;
}

/**
Expand All @@ -204,7 +204,7 @@ public function sendOTP(): array|Collection

return collect($this->phones)
->filter()
->map(fn($p) => $this->normalizeNumber($p))
->map(fn ($p) => $this->normalizeNumber($p))
->map(function ($phone) use ($team) {

rescue(function () use ($team, $phone) {
Expand Down Expand Up @@ -245,7 +245,7 @@ public static function generateWaCallback(string $reference, string $code): arra

return [
'reference' => $reference,
'message' => 'OTP:' . $team . ':' . $code,
'message' => 'OTP:'.$team.':'.$code,
'phone' => $phone,
'scheme' => "whatsapp://send?text=OTP:$team:$code&phone=$phone&abid=$phone",
'url' => "https://wa.me/$phone?text=OTP:$team:$code",
Expand Down

0 comments on commit 7cc8186

Please sign in to comment.