Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
86abc31844 | ||
![]() |
8395b3f001 |
@@ -0,0 +1,72 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create contact',
|
||||
key: 'createContact',
|
||||
description: 'Creates a new contact in your address book.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'First Name',
|
||||
key: 'firstName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Last Name',
|
||||
key: 'lastName',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Email',
|
||||
key: 'email',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Contact List',
|
||||
key: 'contactListId',
|
||||
type: 'dropdown',
|
||||
required: false,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listContactLists',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const { firstName, lastName, email, contactListId } = $.step.parameters;
|
||||
let url = '/v3/contacts';
|
||||
|
||||
if (contactListId) {
|
||||
url = `/v3/contact_lists/${contactListId}/contacts`;
|
||||
}
|
||||
|
||||
const body = {
|
||||
first_name: firstName,
|
||||
last_name: lastName,
|
||||
email,
|
||||
};
|
||||
|
||||
const { data } = await $.http.post(url, body);
|
||||
|
||||
$.setActionItem({
|
||||
raw: data,
|
||||
});
|
||||
},
|
||||
});
|
3
packages/backend/src/apps/surveymonkey/actions/index.js
Normal file
3
packages/backend/src/apps/surveymonkey/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import createContact from './create-contact/index.js';
|
||||
|
||||
export default [createContact];
|
@@ -0,0 +1,4 @@
|
||||
import listContactLists from './list-contact-lists/index.js';
|
||||
import listSurveys from './list-surveys/index.js';
|
||||
|
||||
export default [listSurveys, listContactLists];
|
@@ -0,0 +1,36 @@
|
||||
export default {
|
||||
name: 'List contact lists',
|
||||
key: 'listContactLists',
|
||||
|
||||
async run($) {
|
||||
const contactLists = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
};
|
||||
|
||||
let fetchedSum = 0;
|
||||
let total;
|
||||
do {
|
||||
const { data } = await $.http.get('/v3/contact_lists', { params });
|
||||
|
||||
params.page = params.page + 1;
|
||||
fetchedSum = fetchedSum + params.per_page;
|
||||
total = data.total;
|
||||
|
||||
if (data.data) {
|
||||
for (const contactList of data.data) {
|
||||
contactLists.data.push({
|
||||
value: contactList.id,
|
||||
name: contactList.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (fetchedSum <= total);
|
||||
|
||||
return contactLists;
|
||||
},
|
||||
};
|
@@ -0,0 +1,38 @@
|
||||
export default {
|
||||
name: 'List surveys',
|
||||
key: 'listSurveys',
|
||||
|
||||
async run($) {
|
||||
const surveys = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
per_page: 100,
|
||||
sort_by: 'date_modified',
|
||||
sort_order: 'DESC',
|
||||
};
|
||||
|
||||
let fetchedSum = 0;
|
||||
let total;
|
||||
do {
|
||||
const { data } = await $.http.get(`/v3/surveys`, { params });
|
||||
|
||||
params.page = params.page + 1;
|
||||
fetchedSum = fetchedSum + params.per_page;
|
||||
total = data.total;
|
||||
|
||||
if (data.data) {
|
||||
for (const survey of data.data) {
|
||||
surveys.data.push({
|
||||
value: survey.id,
|
||||
name: survey.title,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (fetchedSum <= total);
|
||||
|
||||
return surveys;
|
||||
},
|
||||
};
|
@@ -2,6 +2,9 @@ import defineApp from '../../helpers/define-app.js';
|
||||
import addAuthHeader from './common/add-auth-header.js';
|
||||
import auth from './auth/index.js';
|
||||
import setBaseUrl from './common/set-base-url.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'SurveyMonkey',
|
||||
@@ -14,4 +17,7 @@ export default defineApp({
|
||||
supportsConnections: true,
|
||||
beforeRequest: [setBaseUrl, addAuthHeader],
|
||||
auth,
|
||||
triggers,
|
||||
dynamicData,
|
||||
actions,
|
||||
});
|
||||
|
3
packages/backend/src/apps/surveymonkey/triggers/index.js
Normal file
3
packages/backend/src/apps/surveymonkey/triggers/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import newResponseNotification from './new-response-notification/index.js';
|
||||
|
||||
export default [newResponseNotification];
|
@@ -0,0 +1,78 @@
|
||||
import Crypto from 'crypto';
|
||||
import isEmpty from 'lodash/isEmpty.js';
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New response notification',
|
||||
key: 'newResponseNotification',
|
||||
type: 'webhook',
|
||||
description: 'Triggers a notification upon the completion of your survey.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Survey',
|
||||
key: 'surveyId',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
description: '',
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listSurveys',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const dataItem = {
|
||||
raw: $.request.body,
|
||||
meta: {
|
||||
internalId: Crypto.randomUUID(),
|
||||
},
|
||||
};
|
||||
|
||||
$.pushTriggerItem(dataItem);
|
||||
},
|
||||
|
||||
async testRun($) {
|
||||
const lastExecutionStep = await $.getLastExecutionStep();
|
||||
|
||||
if (!isEmpty(lastExecutionStep?.dataOut)) {
|
||||
$.pushTriggerItem({
|
||||
raw: lastExecutionStep.dataOut,
|
||||
meta: {
|
||||
internalId: '',
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async registerHook($) {
|
||||
const surveyId = $.step.parameters.surveyId;
|
||||
|
||||
const body = JSON.stringify({
|
||||
name: $.flow.id,
|
||||
subscription_url: $.webhookUrl,
|
||||
event_type: 'response_completed',
|
||||
object_type: 'survey',
|
||||
object_ids: [surveyId],
|
||||
});
|
||||
|
||||
const { data } = await $.http.post('/v3/webhooks?bypass_ping=true', body, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
await $.flow.setRemoteWebhookId(data.id);
|
||||
},
|
||||
|
||||
async unregisterHook($) {
|
||||
await $.http.delete(`/v3/webhooks/${$.flow.remoteWebhookId}`);
|
||||
},
|
||||
});
|
@@ -442,6 +442,8 @@ export default defineConfig({
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
items: [
|
||||
{ text: 'Triggers', link: '/apps/surveymonkey/triggers' },
|
||||
{ text: 'Actions', link: '/apps/surveymonkey/actions' },
|
||||
{ text: 'Connection', link: '/apps/surveymonkey/connection' },
|
||||
],
|
||||
},
|
||||
|
12
packages/docs/pages/apps/surveymonkey/actions.md
Normal file
12
packages/docs/pages/apps/surveymonkey/actions.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
favicon: /favicons/surveymonkey.svg
|
||||
items:
|
||||
- name: Create contact
|
||||
desc: Creates a new contact in your address book.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
12
packages/docs/pages/apps/surveymonkey/triggers.md
Normal file
12
packages/docs/pages/apps/surveymonkey/triggers.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
favicon: /favicons/surveymonkey.svg
|
||||
items:
|
||||
- name: New response notification
|
||||
desc: Triggers a notification upon the completion of your survey.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
@@ -46,6 +46,7 @@ The following integrations are currently supported by Automatisch.
|
||||
- [Spotify](/apps/spotify/actions)
|
||||
- [Strava](/apps/strava/actions)
|
||||
- [Stripe](/apps/stripe/triggers)
|
||||
- [SurveyMonkey](/apps/surveymonkey/triggers)
|
||||
- [Telegram](/apps/telegram-bot/actions)
|
||||
- [Todoist](/apps/todoist/triggers)
|
||||
- [Trello](/apps/trello/actions)
|
||||
|
Reference in New Issue
Block a user