Skip to content

Commit

Permalink
Added support for sentBy in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hellsythe committed Mar 29, 2024
1 parent 252ccae commit be761a5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/Lib/Message/SendMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class SendMessage
{
private array $processedMessage = [];

public function Send(array $request): void
public function Send(array $request, $sentBy = null): void
{
$messageModel = $this->createNewMessage($request);
$messageModel = $this->createNewMessage($request, $sentBy);
$processedMessage = $this->processMessage($messageModel, $request['message']);
$messageResponse = resolve(MessageService::class)
->sendMessage($messageModel->chat->wabaPhone->phone_id, $request['to'], $processedMessage);
$this->finishMessage($messageModel, $messageResponse, $processedMessage);
}

private function createNewMessage(array $request): Message
private function createNewMessage(array $request, $sentBy = null): Message
{
$phoneNumber = WabaPhone::find($request['waba_phone_id']);
$message = new Message();
Expand All @@ -31,6 +31,7 @@ private function createNewMessage(array $request): Message
$message->timestamp = time();
$message->type = $request['message']['type'];
$message->chat_id = $this->getChatId($phoneNumber, $request['to'])->id;
$message->sended_by = $sentBy;
$message->save();

return $message;
Expand Down
4 changes: 2 additions & 2 deletions src/Lib/Template/SendTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class SendTemplate
{
public function Send(WabaPhone $wabaPhone, Template $template, string $to, array $vars = [], $sendedBy = null)
public function Send(WabaPhone $wabaPhone, Template $template, string $to, array $vars = [], $sentBy = null)
{
$template->setVars($vars);
$message = resolve(MessageService::class)
Expand All @@ -23,7 +23,7 @@ public function Send(WabaPhone $wabaPhone, Template $template, string $to, array
$messageModel->message_id = $message['messages'][0]['id'];
$messageModel->type = 'template';
$messageModel->chat_id = $this->getChatId($wabaPhone, $to);
$messageModel->sended_by = $sendedBy;
$messageModel->sended_by = $sentBy;
$messageModel->save();
}

Expand Down
3 changes: 1 addition & 2 deletions src/Listeners/ResponseMessageReady.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function handle(MessageReady $event): void
'body' => $message,
'preview_url' => false,
],

],
]);
], 'BOT');
}
}

0 comments on commit be761a5

Please sign in to comment.