Skip to content

Commit 12a4780

Browse files
authored
Merge pull request #675 from nextcloud/fix/check-if-provider-have-markdown-support
fix: check if provider have markdown support
2 parents 29c3ffb + 1ca477d commit 12a4780

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

lib/Provider/AProvider.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,14 @@ public function getTemplate(IUser $user): ITemplate {
8585

8686
try {
8787
$identifier = $this->stateStorage->get($user, $this->getGatewayName())->getIdentifier() ?? '';
88+
89+
$message = $this->gateway->getSettings()['allow_markdown'] ?? false
90+
? $this->l10n->t('`%s` is your Nextcloud authentication code', [$secret])
91+
: $this->l10n->t('%s is your Nextcloud authentication code', [$secret]);
92+
8893
$this->gateway->send(
8994
$identifier,
90-
$this->l10n->t('%s is your Nextcloud authentication code', [
91-
$secret
92-
]),
95+
$message,
9396
['code' => $secret],
9497
);
9598
} catch (MessageTransmissionException) {

lib/Provider/Channel/SMS/Gateway.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ final public function cliConfigure(InputInterface $input, OutputInterface $outpu
7474
return 0;
7575
}
7676

77+
#[\Override]
78+
public function getSettings(): array {
79+
try {
80+
$provider = $this->getProvider();
81+
} catch (ConfigurationException) {
82+
return static::SCHEMA;
83+
}
84+
return $provider::SCHEMA;
85+
}
86+
7787
#[\Override]
7888
public function isComplete(array $schema = []): bool {
7989
if (empty($schema)) {

lib/Provider/Channel/WhatsApp/Gateway.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
class Gateway extends AGateway {
3737
public const SCHEMA = [
3838
'name' => 'WhatsApp',
39+
'allow_markdown' => true,
3940
'fields' => [
4041
['field' => 'base_url', 'prompt' => 'Base URL to your WhatsApp API endpoint:'],
4142
],
@@ -57,9 +58,6 @@ public function __construct(
5758

5859
#[\Override]
5960
public function send(string $identifier, string $message, array $extra = []): void {
60-
if (empty($message)) {
61-
$message = $this->l10n->t('`%s` is your Nextcloud verification code.', [$extra['code']]);
62-
}
6361
$this->logger->debug("sending whatsapp message to $identifier, message: $message");
6462

6563
$response = $this->getSessionStatus();

lib/Provider/Gateway/AGateway.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function isComplete(array $schema = []): bool {
3737
}
3838
$set = $this->appConfig->getKeys(Application::APP_ID);
3939
$fields = array_column($schema['fields'], 'field');
40-
$fields = array_map(fn ($f) => $this->getProviderId() . '_' . $f, $fields);
40+
$providerId = $schema['id'] ?? $this->getProviderId();
41+
$fields = array_map(fn ($f) => $providerId . '_' . $f, $fields);
4142
$intersect = array_intersect($fields, $set);
4243
return count($intersect) === count($fields);
4344
}

lib/Service/SetupService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ public function startSetup(IUser $user, string $gatewayName, string $identifier)
5959
$verificationNumber = $this->random->generate(6, ISecureRandom::CHAR_DIGITS);
6060
$gateway = $this->gatewayFactory->get($gatewayName);
6161
try {
62+
$message = match ($gateway->getSettings()['allow_markdown'] ?? false) {
63+
true => $this->l10n->t('`%s` is your verification code.', [$verificationNumber]),
64+
default => $this->l10n->t('%s is your verification code.', [$verificationNumber]),
65+
};
6266
$gateway->send(
6367
$identifier,
64-
$this->l10n->t('%s is your verification code.', [$verificationNumber]),
68+
$message,
6569
['code' => $verificationNumber],
6670
);
6771
} catch (MessageTransmissionException $ex) {

0 commit comments

Comments
 (0)