Skip to content

Commit

Permalink
fix(webex): Use a generated URL instead of hardcoded one in bot answer (
Browse files Browse the repository at this point in the history
  • Loading branch information
damienalexandre committed Mar 22, 2024
1 parent 93a4731 commit 6fbcc13
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Webex/MessageSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

use JoliCode\SecretSanta\Exception\MessageSendFailedException;
use JoliCode\SecretSanta\Model\SecretSanta;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class MessageSender
{
public function __construct(readonly private HttpClientInterface $client, readonly private string $webexBotToken)
{
public function __construct(
readonly private HttpClientInterface $client,
readonly private RouterInterface $router,
readonly private string $webexBotToken
) {
}

public function sendSecretMessage(SecretSanta $secretSanta, string $giver, string $receiver, bool $isSample): void
Expand Down Expand Up @@ -116,14 +120,20 @@ public function sendAdminMessage(SecretSanta $secretSanta, string $code, string

public function sendDummyBotAnswer(string $string): void
{
$webexLandingUrl = $this->router->generate('webex_landing', referenceType: RouterInterface::ABSOLUTE_URL);

$this->client->request('POST', 'https://webexapis.com/v1/messages', [
'auth_bearer' => $this->webexBotToken,
'headers' => [
'accept' => 'application/json',
],
'json' => [
'toPersonId' => $string,
'markdown' => 'Hello, thanks for reaching out! If you wish to run a Secret Santa, you must go to https://secret-santa.team/landing/webex and start over!',
'markdown' => sprintf(
'Hello, thanks for reaching out! If you wish to run a Secret Santa,
you must go to %s and click on "Run on Webex"!',
$webexLandingUrl
),
],
]);
}
Expand Down

0 comments on commit 6fbcc13

Please sign in to comment.