Skip to content

Commit ab9b1de

Browse files
committed
Adds getResponseUrl helper to payload
Also fixes a bug in ShellExecDeferrer that prevented logs from working in deferred processes.
1 parent a650d04 commit ab9b1de

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/Context.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,9 @@ public function error(string $error): void
342342
*/
343343
public function respond($message, ?string $url = null): void
344344
{
345-
if (!$url) {
346-
$url = (string) $this->payload->getOneOf(['response_url', 'response_urls.0.response_url'], true);
345+
$url ??= $this->payload->getResponseUrl();
346+
if ($url === null) {
347+
throw new Exception('Cannot respond: Response URL must be available in the payload or explicitly provided');
347348
}
348349

349350
if (!isset($this->respondClient)) {

src/Contexts/Payload.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,30 @@ public function getMetadata(): PrivateMetadata
179179
return PrivateMetadata::decode($this->get('view.private_metadata', true));
180180
}
181181

182+
/**
183+
* Get the response URL from the payload, if present.
184+
*
185+
* Is present for anything that has a conversation context.
186+
*
187+
* @return string|null
188+
*/
189+
public function getResponseUrl(): ?string
190+
{
191+
$responseUrl = $this->getOneOf(['response_url', 'response_urls.0.response_url']);
192+
if ($responseUrl === null) {
193+
$metadata = $this->get('view.private_metadata');
194+
if ($metadata !== null) {
195+
$responseUrl = PrivateMetadata::decode($metadata)->get('response_url');
196+
}
197+
}
198+
199+
if ($responseUrl !== null) {
200+
$responseUrl = (string) $responseUrl;
201+
}
202+
203+
return $responseUrl;
204+
}
205+
182206
/**
183207
* Gets indentifying information about the payload for the purposes of logging/debugging.
184208
*

src/Deferral/ShellExecDeferrer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function defer(Context $context): void
4141
{
4242
$context->logger()->debug('Deferring processing by running a command with shell_exec in the background');
4343
$data = escapeshellarg($this->serializeContext($context));
44-
$command = "cd {$this->dir};nohup {$this->script} {$data} > /dev/null 2>&1 &";
44+
$command = "cd {$this->dir};nohup {$this->script} {$data} > /dev/null &";
4545
shell_exec($command);
4646
}
4747

0 commit comments

Comments
 (0)