Merge pull request #666 from automatisch/discord/send-message-to-channel
feat(discord): add send message to channel action
This commit is contained in:
@@ -1 +1,5 @@
|
||||
export default [];
|
||||
import sendMessageToChannel from "./send-message-to-channel";
|
||||
|
||||
export default [
|
||||
sendMessageToChannel
|
||||
];
|
||||
|
@@ -0,0 +1,58 @@
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Send a message to channel',
|
||||
key: 'sendMessageToChannel',
|
||||
description: 'Send a message to a specific channel you specify.',
|
||||
substeps: [
|
||||
{
|
||||
key: 'chooseConnection',
|
||||
name: 'Choose connection',
|
||||
},
|
||||
{
|
||||
key: 'chooseAction',
|
||||
name: 'Set up action',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Channel',
|
||||
key: 'channel',
|
||||
type: 'dropdown' as const,
|
||||
required: true,
|
||||
description: 'Pick a channel to send the message to.',
|
||||
variables: false,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listChannels',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Message text',
|
||||
key: 'message',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'The content of your new message.',
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test action',
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const data = {
|
||||
content: $.step.parameters.message as string,
|
||||
};
|
||||
const response = await $.http?.post(`/channels/${$.step.parameters.channel}/messages`, data);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
@@ -13,6 +13,7 @@ export default async function createAuthData($: IGlobalVariable) {
|
||||
client_id: $.auth.data.consumerKey as string,
|
||||
redirect_uri: callbackUrl,
|
||||
response_type: 'code',
|
||||
permissions: '2146958591',
|
||||
scope: scopes.join(' '),
|
||||
});
|
||||
|
||||
|
@@ -39,6 +39,18 @@ export default {
|
||||
description: null,
|
||||
docUrl: 'https://automatisch.io/docs/discord#consumer-secret',
|
||||
clickToCopy: false
|
||||
},
|
||||
{
|
||||
key: 'botToken',
|
||||
label: 'Bot token',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description: null,
|
||||
docUrl: 'https://automatisch.io/docs/discord#bot-token',
|
||||
clickToCopy: false
|
||||
}
|
||||
],
|
||||
authenticationSteps: [
|
||||
@@ -62,6 +74,10 @@ export default {
|
||||
{
|
||||
name: 'consumerSecret',
|
||||
value: '{fields.consumerSecret}'
|
||||
},
|
||||
{
|
||||
name: 'botToken',
|
||||
value: '{fields.botToken}'
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -154,6 +170,10 @@ export default {
|
||||
{
|
||||
name: 'consumerSecret',
|
||||
value: '{fields.consumerSecret}'
|
||||
},
|
||||
{
|
||||
name: 'botToken',
|
||||
value: '{fields.botToken}'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -28,6 +28,10 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
expires_in: expiresIn,
|
||||
scope: scope,
|
||||
token_type: tokenType,
|
||||
guild: {
|
||||
id: guildId,
|
||||
name: guildName,
|
||||
}
|
||||
} = verifiedCredentials;
|
||||
|
||||
await $.auth.set({
|
||||
@@ -44,6 +48,8 @@ const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
userId: user.id,
|
||||
screenName: user.username,
|
||||
email: user.email,
|
||||
guildId,
|
||||
guildName,
|
||||
});
|
||||
};
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const { tokenType, accessToken } = $.auth.data;
|
||||
if (tokenType && accessToken) {
|
||||
requestConfig.headers.Authorization = `${tokenType} ${accessToken}`;
|
||||
const { tokenType, botToken } = $.auth.data;
|
||||
if (tokenType && botToken) {
|
||||
requestConfig.headers.Authorization = `Bot ${botToken}`;
|
||||
}
|
||||
|
||||
return requestConfig;
|
||||
|
@@ -1,3 +1,3 @@
|
||||
const scopes = ['identify', 'email'];
|
||||
const scopes = ['bot', 'identify'];
|
||||
|
||||
export default scopes;
|
||||
|
5
packages/backend/src/apps/discord/data/index.ts
Normal file
5
packages/backend/src/apps/discord/data/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import listChannels from "./list-channels";
|
||||
|
||||
export default [
|
||||
listChannels,
|
||||
];
|
@@ -0,0 +1,32 @@
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default {
|
||||
name: 'List channels',
|
||||
key: 'listChannels',
|
||||
|
||||
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 text channels only
|
||||
return channel.type === 0;
|
||||
})
|
||||
.map((channel: IJSONObject) => {
|
||||
return {
|
||||
value: channel.id,
|
||||
name: channel.name,
|
||||
};
|
||||
});
|
||||
|
||||
return channels;
|
||||
},
|
||||
};
|
@@ -1,6 +1,7 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import addAuthHeader from './common/add-auth-header';
|
||||
import auth from './auth';
|
||||
import data from './data';
|
||||
import actions from './actions';
|
||||
import triggers from './triggers';
|
||||
|
||||
@@ -15,6 +16,7 @@ export default defineApp({
|
||||
primaryColor: '5865f2',
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
data,
|
||||
triggers,
|
||||
actions,
|
||||
});
|
||||
|
Reference in New Issue
Block a user