Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(discord): add createEvent action #1450

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import defineAction from '../../../../helpers/define-action';

export default defineAction({
name: 'Create a new scheduled event',
key: 'createNewScheduledEvent',
description: 'Creates a new event',
arguments: [
{
label: 'Type',
key: 'entityType',
type: 'dropdown' as const,
required: true,
variables: true,
options: [
{ label: 'Stage channel', value: 1 },
{ label: 'Voice channel', value: 2 },
{ label: 'External', value: 3 }
],
additionalFields: {
type: 'query',
name: 'getDynamicFields',
arguments: [
{
name: 'key',
value: 'listExternalScheduledEventFields',
},
{
name: 'parameters.entityType',
value: '{parameters.entityType}',
},
],
},
},
{
label: 'Name',
key: 'name',
type: 'string' as const,
required: true,
variables: true,
},
{
label: 'Description',
key: 'description',
type: 'string' as const,
required: false,
variables: true,
},
{
label: 'Image',
key: 'image',
type: 'string' as const,
required: false,
description: 'Image as DataURI scheme [data:image/<jpeg/png/gif>;base64,BASE64_ENCODED_<JPEG/PNG/GIF>_IMAGE_DATA]',
variables: true,
},
],

async run($) {
type entity_metadata = {
location: string
}

type guild_event = {
channel_id: number,
name: string,
privacy_level: number,
scheduled_start_time: string,
scheduled_end_time?: string,
description?: string,
entity_type?: number,
entity_metadata?: entity_metadata,
image?: string, //data:image/jpeg;base64,BASE64_ENCODED_JPEG_IMAGE_DATA
}


const data: guild_event = {
channel_id: $.step.parameters.channel_id as number,
name: $.step.parameters.name as string,
privacy_level: 2,
scheduled_start_time: $.step.parameters.scheduledStartTime as string,
scheduled_end_time: $.step.parameters.scheduledEndTime as string,
description: $.step.parameters.description as string,
entity_type: $.step.parameters.entityType as number,
image: $.step.parameters.image as string,
};

const isExternal = $.step.parameters.entityType === 3;
if (isExternal) {
data.entity_metadata = {
location: $.step.parameters.location as string,
};
data.channel_id = null;
}

const response = await $.http?.post(
`/guilds/${$.auth.data.guildId}/scheduled-events`,
data
);

$.setActionItem({ raw: response.data });
},
});
3 changes: 2 additions & 1 deletion packages/backend/src/apps/discord/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sendMessageToChannel from './send-message-to-channel';
import createNewScheduledEvent from './create-new-scheduled-event';

export default [sendMessageToChannel];
export default [sendMessageToChannel, createNewScheduledEvent];
3 changes: 2 additions & 1 deletion packages/backend/src/apps/discord/dynamic-data/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import listChannels from './list-channels';
import listVoiceChannels from './list-voice-channels';

export default [listChannels];
export default [listChannels, listVoiceChannels];
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';

export default {
name: 'List voice channels',
key: 'listVoiceChannels',

async run($: IGlobalVariable) {
const channels: {
data: IJSONObject[];
error: IJSONObject | null;
} = {
data: [],
error: null,
};

const response = await $.http.get(
`/guilds/${$.auth.data.guildId}/channels`
);

channels.data = response.data
.filter((channel: IJSONObject) => {
// filter in voice and stage channels only
return channel.type === 2 || channel.type === 13;
})
.map((channel: IJSONObject) => {
return {
value: channel.id,
name: channel.name,
};
});

return channels;
},
};
3 changes: 3 additions & 0 deletions packages/backend/src/apps/discord/dynamic-fields/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import listExternalScheduledEventFields from './list-external-scheduled-event-fields';

export default [listExternalScheduledEventFields];
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { IGlobalVariable } from '@automatisch/types';
export default {
name: 'List external scheduled event fields',
key: 'listExternalScheduledEventFields',

async run($: IGlobalVariable) {
const isExternal = $.step.parameters.entityType === 3;

if (isExternal) {
return [
{
label: 'Location',
key: 'location',
type: 'string' as const,
required: true,
description: 'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
variables: true,
},
{
label: 'Start-Time',
key: 'scheduledStartTime',
type: 'string' as const,
required: true,
description: 'The time the event will start [ISO8601]',
variables: true,
},
{
label: 'End-Time',
key: 'scheduledEndTime',
type: 'string' as const,
required: true,
description: 'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
variables: true,
},
];
}

return [
{
label: 'Channel',
key: 'channel_id',
type: 'dropdown' as const,
required: true,
description: 'Pick a voice or stage channel to link the event to. This will be omitted if type is EXTERNAL',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listVoiceChannels',
},
],
},
},
{
label: 'Location',
key: 'location',
type: 'string' as const,
required: false,
description: 'The location of the event (1-100 characters). This will be omitted if type is NOT EXTERNAL',
variables: true,
},
{
label: 'Start-Time',
key: 'scheduledStartTime',
type: 'string' as const,
required: true,
description: 'The time the event will start [ISO8601]',
variables: true,
},
{
label: 'End-Time',
key: 'scheduledEndTime',
type: 'string' as const,
required: false,
description: 'The time the event will end [ISO8601]. This will be omitted if type is NOT EXTERNAL',
variables: true,
},
];
},
};
2 changes: 2 additions & 0 deletions packages/backend/src/apps/discord/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import auth from './auth';
import dynamicData from './dynamic-data';
import actions from './actions';
import triggers from './triggers';
import dynamicFields from './dynamic-fields';

export default defineApp({
name: 'Discord',
Expand All @@ -17,6 +18,7 @@ export default defineApp({
beforeRequest: [addAuthHeader],
auth,
dynamicData,
dynamicFields,
triggers,
actions,
});
2 changes: 2 additions & 0 deletions packages/docs/pages/apps/discord/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ favicon: /favicons/discord.svg
items:
- name: Send a message to channel
desc: Sends a message to a specific channel you specify.
- name: Create a new scheduled event
desc: Creates a new scheduled event.
---

<script setup>
Expand Down