-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14160 from nextcloud/feat/noid/event-based-bots
feat(bots): Event based bots
- Loading branch information
Showing
26 changed files
with
1,318 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Talk\Events; | ||
|
||
use OCP\EventDispatcher\Event; | ||
|
||
/** | ||
* @psalm-type ChatMessageData = array{ | ||
* type: 'Activity'|'Create', | ||
* actor: array{ | ||
* type: 'Person', | ||
* id: non-empty-string, | ||
* name: non-empty-string, | ||
* talkParticipantType: non-empty-string, | ||
* }, | ||
* object: array{ | ||
* type: 'Note', | ||
* id: non-empty-string, | ||
* name: string, | ||
* content: non-empty-string, | ||
* mediaType: 'text/markdown'|'text/plain', | ||
* }, | ||
* target: array{ | ||
* type: 'Collection', | ||
* id: non-empty-string, | ||
* name: non-empty-string, | ||
* }, | ||
* } | ||
* @psalm-type BotManagementData = array{ | ||
* type: 'Join'|'Leave', | ||
* actor: array{ | ||
* type: 'Application', | ||
* id: non-empty-string, | ||
* name: non-empty-string, | ||
* }, | ||
* object: array{ | ||
* type: 'Collection', | ||
* id: non-empty-string, | ||
* name: non-empty-string, | ||
* }, | ||
* } | ||
* @psalm-type InvocationData = ChatMessageData|BotManagementData | ||
*/ | ||
class BotInvokeEvent extends Event { | ||
/** @var list<string> */ | ||
protected array $reactions = []; | ||
/** @var list<array{message: string, referenceId: string, reply: bool|int, silent: bool}> */ | ||
protected array $answers = []; | ||
|
||
/** | ||
* @param InvocationData $message | ||
*/ | ||
public function __construct( | ||
protected string $botUrl, | ||
protected array $message, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function getBotUrl(): string { | ||
return $this->botUrl; | ||
} | ||
|
||
/** | ||
* @return InvocationData | ||
*/ | ||
public function getMessage(): array { | ||
return $this->message; | ||
} | ||
|
||
public function addReaction(string $emoji): void { | ||
$this->reactions[] = $emoji; | ||
} | ||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
public function getReactions(): array { | ||
return $this->reactions; | ||
} | ||
|
||
public function addAnswer(string $message, bool|int $reply = false, bool $silent = false, string $referenceId = ''): void { | ||
$this->answers[] = [ | ||
'message' => $message, | ||
'referenceId' => $referenceId, | ||
'reply' => $reply, | ||
'silent' => $silent, | ||
]; | ||
} | ||
|
||
/** | ||
* @return list<array{message: string, referenceId: string, reply: bool|int, silent: bool}> | ||
*/ | ||
public function getAnswers(): array { | ||
return $this->answers; | ||
} | ||
} |
Oops, something went wrong.