Fixes #3983 -- Add GetMeRadio webhooks support.

This commit is contained in:
Buster Neece 2023-08-29 07:02:13 -05:00
parent c312a49773
commit 47a4c00df8
No known key found for this signature in database
6 changed files with 132 additions and 3 deletions

View File

@ -75,6 +75,7 @@ export enum WebhookType {
Email = 'email',
TuneIn = 'tunein',
RadioDe = 'radiode',
GetMeRadio = 'getmeradio',
Discord = 'discord',
Telegram = 'telegram',
Mastodon = 'mastodon',
@ -96,11 +97,15 @@ export function useTypeDetails() {
},
[WebhookType.TuneIn]: {
title: $gettext('TuneIn AIR'),
description: $gettext('Send song metadata changes to TuneIn.')
description: $gettext('Send song metadata changes to %{service}.', {service: 'TuneIn'})
},
[WebhookType.RadioDe]: {
title: $gettext('Radio.de'),
description: $gettext('Send song metadata changes to Radio.de.')
description: $gettext('Send song metadata changes to %{service}.', {service: 'Radio.de'})
},
[WebhookType.GetMeRadio]: {
title: $gettext('GetMeRadio'),
description: $gettext('Send song metadata changes to %{service}', {service: 'GetMeRadio'})
},
[WebhookType.Discord]: {
title: $gettext('Discord Webhook'),
@ -129,6 +134,7 @@ export function getTriggers(type: WebhookType) {
switch(type) {
case WebhookType.TuneIn:
case WebhookType.RadioDe:
case WebhookType.GetMeRadio:
case WebhookType.GoogleAnalyticsV4:
case WebhookType.MatomoAnalytics:
return [];

View File

@ -49,6 +49,7 @@ import ModalForm from "~/components/Common/ModalForm.vue";
import {getTriggers, WebhookType} from "~/components/Entity/Webhooks";
import Tabs from "~/components/Common/Tabs.vue";
import RadioDe from "~/components/Stations/Webhooks/Form/RadioDe.vue";
import GetMeRadio from "~/components/Stations/Webhooks/Form/GetMeRadio.vue";
const props = defineProps({
...baseEditModalProps,
@ -79,6 +80,7 @@ const webhookComponents = {
[WebhookType.Email]: Email,
[WebhookType.TuneIn]: Tunein,
[WebhookType.RadioDe]: RadioDe,
[WebhookType.GetMeRadio]: GetMeRadio,
[WebhookType.Discord]: Discord,
[WebhookType.Telegram]: Telegram,
[WebhookType.Mastodon]: Mastodon,

View File

@ -0,0 +1,62 @@
<template>
<tab
:label="title"
:item-header-class="tabClass"
>
<div class="row g-3">
<form-group-field
id="form_config_token"
class="col-md-6"
:field="v$.config.token"
:label="$gettext('API Token')"
:description="$gettext('This can be retrieved from the GetMeRadio dashboard.')"
/>
<form-group-field
id="form_config_station_id"
class="col-md-6"
:field="v$.config.station_id"
:label="$gettext('GetMeRadio Station ID')"
:description="$gettext('This is a 3-5 digit number.')"
/>
</div>
</tab>
</template>
<script setup lang="ts">
import FormGroupField from "~/components/Form/FormGroupField.vue";
import {useVModel} from "@vueuse/core";
import {useVuelidateOnFormTab} from "~/functions/useVuelidateOnFormTab";
import {required} from "@vuelidate/validators";
import Tab from "~/components/Common/Tab.vue";
const props = defineProps({
title: {
type: String,
required: true
},
form: {
type: Object,
required: true
}
});
const emit = defineEmits(['update:form']);
const form = useVModel(props, 'form', emit);
const {v$, tabClass} = useVuelidateOnFormTab(
{
config: {
token: {required},
station_id: {required}
}
},
form,
{
config: {
token: '',
station_id: '',
}
}
);
</script>

View File

@ -25,7 +25,8 @@
:title="$gettext('Station Directories')"
:types="buildTypeInfo([
WebhookType.TuneIn,
WebhookType.RadioDe
WebhookType.RadioDe,
WebhookType.GetMeRadio
])"
@select="selectType"
/>

View File

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace App\Webhook\Connector;
use App\Entity\Api\NowPlaying\NowPlaying;
use App\Entity\Station;
use App\Entity\StationWebhook;
use App\Webhook\Enums\WebhookTriggers;
final class GetMeRadio extends AbstractConnector
{
protected function webhookShouldTrigger(StationWebhook $webhook, array $triggers = []): bool
{
return in_array(WebhookTriggers::SongChanged->value, $triggers, true);
}
/**
* @inheritDoc
*/
public function dispatch(
Station $station,
StationWebhook $webhook,
NowPlaying $np,
array $triggers
): void {
$config = $webhook->getConfig();
if (
empty($config['token'])
|| empty($config['station_id'])
) {
throw $this->incompleteConfigException($webhook);
}
$this->logger->debug('Dispatching GetMeRadio API call...');
$messageBody = [
'token' => $config['token'],
'station_id' => $config['station_id'],
'title' => $np->now_playing?->song?->title,
'artist' => $np->now_playing?->song?->artist,
];
$response = $this->httpClient->get(
'https://services.getmeradio.com/api/song_update/',
[
'query' => $messageBody,
]
);
$this->logHttpResponse($webhook, $response, $messageBody);
}
}

View File

@ -7,6 +7,7 @@ namespace App\Webhook\Enums;
use App\Webhook\Connector\Discord;
use App\Webhook\Connector\Email;
use App\Webhook\Connector\Generic;
use App\Webhook\Connector\GetMeRadio;
use App\Webhook\Connector\GoogleAnalyticsV4;
use App\Webhook\Connector\Mastodon;
use App\Webhook\Connector\MatomoAnalytics;
@ -21,6 +22,7 @@ enum WebhookTypes: string
case TuneIn = 'tunein';
case RadioDe = 'radiode';
case GetMeRadio = 'getmeradio';
case Discord = 'discord';
case Telegram = 'telegram';
@ -43,6 +45,7 @@ enum WebhookTypes: string
self::Email => Email::class,
self::TuneIn => TuneIn::class,
self::RadioDe => RadioDe::class,
self::GetMeRadio => GetMeRadio::class,
self::Discord => Discord::class,
self::Telegram => Telegram::class,
self::Mastodon => Mastodon::class,