Add Activepieces integration for workflow automation
- Add Activepieces fork with SmoothSchedule custom piece - Create integrations app with Activepieces service layer - Add embed token endpoint for iframe integration - Create Automations page with embedded workflow builder - Add sidebar visibility fix for embed mode - Add list inactive customers endpoint to Public API - Include SmoothSchedule triggers: event created/updated/cancelled - Include SmoothSchedule actions: create/update/cancel events, list resources/services/customers 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Google Forms": "Google Forms",
|
||||
"Receive form responses from Google Forms": "Receive form responses from Google Forms",
|
||||
"Custom API Call": "Custom API Call",
|
||||
"Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
|
||||
"Method": "Method",
|
||||
"Headers": "Headers",
|
||||
"Query Parameters": "Query Parameters",
|
||||
"Body": "Body",
|
||||
"No Error on Failure": "No Error on Failure",
|
||||
"Timeout (in seconds)": "Timeout (in seconds)",
|
||||
"Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
|
||||
"GET": "GET",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "DELETE",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "New Response",
|
||||
"Triggers when there is new response": "Triggers when there is new response",
|
||||
"Form": "Form",
|
||||
"Include Team Drive Forms": "Include Team Drive Forms",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determines if forms from Team Drives should be included in the results."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Erhalte Formularantworten von Google Formularen",
|
||||
"Custom API Call": "Eigener API-Aufruf",
|
||||
"Make a custom API call to a specific endpoint": "Einen benutzerdefinierten API-Aufruf an einen bestimmten Endpunkt machen",
|
||||
"Method": "Methode",
|
||||
"Headers": "Kopfzeilen",
|
||||
"Query Parameters": "Abfrageparameter",
|
||||
"Body": "Körper",
|
||||
"Response is Binary ?": "Antwort ist binär?",
|
||||
"No Error on Failure": "Kein Fehler bei Fehler",
|
||||
"Timeout (in seconds)": "Timeout (in Sekunden)",
|
||||
"Authorization headers are injected automatically from your connection.": "Autorisierungs-Header werden automatisch von Ihrer Verbindung injiziert.",
|
||||
"Enable for files like PDFs, images, etc..": "Aktivieren für Dateien wie PDFs, Bilder, etc..",
|
||||
"GET": "ERHALTEN",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "LÖSCHEN",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "Neue Antwort",
|
||||
"Triggers when there is new response": "Wird ausgelöst, wenn eine neue Antwort vorhanden ist",
|
||||
"Form": "Formular",
|
||||
"Include Team Drive Forms": "Teamlaufwerksformulare einbeziehen",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Legt fest, ob Formulare von Team Drives in die Ergebnisse aufgenommen werden sollen."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Recibir respuestas de formularios de Google Forms",
|
||||
"Custom API Call": "Llamada API personalizada",
|
||||
"Make a custom API call to a specific endpoint": "Hacer una llamada API personalizada a un extremo específico",
|
||||
"Method": "Método",
|
||||
"Headers": "Encabezados",
|
||||
"Query Parameters": "Parámetros de consulta",
|
||||
"Body": "Cuerpo",
|
||||
"Response is Binary ?": "¿Respuesta es binaria?",
|
||||
"No Error on Failure": "No hay ningún error en fallo",
|
||||
"Timeout (in seconds)": "Tiempo de espera (en segundos)",
|
||||
"Authorization headers are injected automatically from your connection.": "Las cabeceras de autorización se inyectan automáticamente desde tu conexión.",
|
||||
"Enable for files like PDFs, images, etc..": "Activar para archivos como PDFs, imágenes, etc.",
|
||||
"GET": "RECOGER",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "BORRAR",
|
||||
"HEAD": "LIMPIO",
|
||||
"New Response": "Nueva respuesta",
|
||||
"Triggers when there is new response": "Dispara cuando hay nueva respuesta",
|
||||
"Form": "Forma",
|
||||
"Include Team Drive Forms": "Incluye Formularios de Unidad de Equipo",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determina si los formularios de Team Drives deben ser incluidos en los resultados."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Recevoir des réponses de formulaires de Google Forms",
|
||||
"Custom API Call": "Appel API personnalisé",
|
||||
"Make a custom API call to a specific endpoint": "Passez un appel API personnalisé à un endpoint spécifique",
|
||||
"Method": "Méthode",
|
||||
"Headers": "Headers",
|
||||
"Query Parameters": "Paramètres de requête",
|
||||
"Body": "Body",
|
||||
"Response is Binary ?": "La réponse est Binaire ?",
|
||||
"No Error on Failure": "Aucune erreur en cas d'échec",
|
||||
"Timeout (in seconds)": "Délai d'attente (en secondes)",
|
||||
"Authorization headers are injected automatically from your connection.": "Les Headers d'autorisation sont injectés automatiquement à partir de votre connexion.",
|
||||
"Enable for files like PDFs, images, etc..": "Activer pour les fichiers comme les PDF, les images, etc.",
|
||||
"GET": "GET",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "DELETE",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "Nouvelle réponse",
|
||||
"Triggers when there is new response": "Se déclenche lorsqu'il y a une nouvelle réponse",
|
||||
"Form": "Formulaire",
|
||||
"Include Team Drive Forms": "Inclure les formulaires Team Drive",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Détermine si les formulaires de Team Drives doivent être inclus dans les résultats."
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Google Forms": "Google Forms",
|
||||
"Receive form responses from Google Forms": "Receive form responses from Google Forms",
|
||||
"Custom API Call": "Custom API Call",
|
||||
"Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
|
||||
"Method": "Method",
|
||||
"Headers": "Headers",
|
||||
"Query Parameters": "Query Parameters",
|
||||
"Body": "Body",
|
||||
"No Error on Failure": "No Error on Failure",
|
||||
"Timeout (in seconds)": "Timeout (in seconds)",
|
||||
"Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
|
||||
"GET": "GET",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "DELETE",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "New Response",
|
||||
"Triggers when there is new response": "Triggers when there is new response",
|
||||
"Form": "Form",
|
||||
"Include Team Drive Forms": "Include Team Drive Forms",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determines if forms from Team Drives should be included in the results."
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Google Forms": "Google Forms",
|
||||
"Receive form responses from Google Forms": "Receive form responses from Google Forms",
|
||||
"Custom API Call": "Custom API Call",
|
||||
"Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
|
||||
"Method": "Method",
|
||||
"Headers": "Headers",
|
||||
"Query Parameters": "Query Parameters",
|
||||
"Body": "Body",
|
||||
"No Error on Failure": "No Error on Failure",
|
||||
"Timeout (in seconds)": "Timeout (in seconds)",
|
||||
"Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
|
||||
"GET": "GET",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "DELETE",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "New Response",
|
||||
"Triggers when there is new response": "Triggers when there is new response",
|
||||
"Form": "Form",
|
||||
"Include Team Drive Forms": "Include Team Drive Forms",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determines if forms from Team Drives should be included in the results."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Googleフォームからフォームの応答を受信する",
|
||||
"Custom API Call": "カスタムAPI通話",
|
||||
"Make a custom API call to a specific endpoint": "特定のエンドポイントへのカスタム API コールを実行します。",
|
||||
"Method": "方法",
|
||||
"Headers": "ヘッダー",
|
||||
"Query Parameters": "クエリパラメータ",
|
||||
"Body": "本文",
|
||||
"Response is Binary ?": "応答はバイナリですか?",
|
||||
"No Error on Failure": "失敗時にエラーはありません",
|
||||
"Timeout (in seconds)": "タイムアウト(秒)",
|
||||
"Authorization headers are injected automatically from your connection.": "認証ヘッダは接続から自動的に注入されます。",
|
||||
"Enable for files like PDFs, images, etc..": "PDF、画像などのファイルを有効にします。",
|
||||
"GET": "取得",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "削除",
|
||||
"HEAD": "頭",
|
||||
"New Response": "新しい回答",
|
||||
"Triggers when there is new response": "新しい応答があるときにトリガーします",
|
||||
"Form": "フォーム",
|
||||
"Include Team Drive Forms": "チームドライブフォームを含める",
|
||||
"Determines if forms from Team Drives should be included in the results.": "チームドライブのフォームを結果に含めるかどうかを指定します。"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Formulierantwoorden ontvangen van Google Formulieren",
|
||||
"Custom API Call": "Custom API Call",
|
||||
"Make a custom API call to a specific endpoint": "Maak een aangepaste API call naar een specifiek eindpunt",
|
||||
"Method": "Methode",
|
||||
"Headers": "Kopteksten",
|
||||
"Query Parameters": "Query parameters",
|
||||
"Body": "Lichaam",
|
||||
"Response is Binary ?": "Antwoord is binair?",
|
||||
"No Error on Failure": "Geen fout bij fout",
|
||||
"Timeout (in seconds)": "Time-out (in seconden)",
|
||||
"Authorization headers are injected automatically from your connection.": "Autorisatie headers worden automatisch geïnjecteerd vanuit uw verbinding.",
|
||||
"Enable for files like PDFs, images, etc..": "Inschakelen voor bestanden zoals PDF's, afbeeldingen etc..",
|
||||
"GET": "KRIJG",
|
||||
"POST": "POSTE",
|
||||
"PATCH": "BEKIJK",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "VERWIJDEREN",
|
||||
"HEAD": "HOOFD",
|
||||
"New Response": "Nieuw Antwoord",
|
||||
"Triggers when there is new response": "Triggert wanneer er een nieuwe reactie is",
|
||||
"Form": "Vorm",
|
||||
"Include Team Drive Forms": "Inclusief Team Drive formulieren",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Bepaalt of vormen van Team Drives moeten worden opgenomen in de resultaten."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Receber respostas de formulários do Google Formulários",
|
||||
"Custom API Call": "Chamada de API personalizada",
|
||||
"Make a custom API call to a specific endpoint": "Faça uma chamada de API personalizada para um ponto de extremidade específico",
|
||||
"Method": "Método",
|
||||
"Headers": "Cabeçalhos",
|
||||
"Query Parameters": "Parâmetros da consulta",
|
||||
"Body": "Conteúdo",
|
||||
"Response is Binary ?": "A resposta é binária ?",
|
||||
"No Error on Failure": "Nenhum erro no Failure",
|
||||
"Timeout (in seconds)": "Tempo limite (em segundos)",
|
||||
"Authorization headers are injected automatically from your connection.": "Os cabeçalhos de autorização são inseridos automaticamente a partir da sua conexão.",
|
||||
"Enable for files like PDFs, images, etc..": "Habilitar para arquivos como PDFs, imagens, etc..",
|
||||
"GET": "OBTER",
|
||||
"POST": "POSTAR",
|
||||
"PATCH": "COMPRAR",
|
||||
"PUT": "COLOCAR",
|
||||
"DELETE": "EXCLUIR",
|
||||
"HEAD": "CABEÇA",
|
||||
"New Response": "Nova Resposta",
|
||||
"Triggers when there is new response": "Dispara quando há uma nova resposta",
|
||||
"Form": "Formulário",
|
||||
"Include Team Drive Forms": "Incluir Formulários de Drive do Time",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determina se os formulários de unidades de equipe devem ser incluídos nos resultados."
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Google Forms": "Формы Google",
|
||||
"Receive form responses from Google Forms": "Получать ответы в форме от Google Forms",
|
||||
"Custom API Call": "Пользовательский вызов API",
|
||||
"Make a custom API call to a specific endpoint": "Сделать пользовательский API вызов к определенной конечной точке",
|
||||
"Method": "Метод",
|
||||
"Headers": "Заголовки",
|
||||
"Query Parameters": "Параметры запроса",
|
||||
"Body": "Тело",
|
||||
"No Error on Failure": "Нет ошибок при ошибке",
|
||||
"Timeout (in seconds)": "Таймаут (в секундах)",
|
||||
"Authorization headers are injected automatically from your connection.": "Заголовки авторизации включаются автоматически из вашего соединения.",
|
||||
"GET": "ПОЛУЧИТЬ",
|
||||
"POST": "ПОСТ",
|
||||
"PATCH": "ПАТЧ",
|
||||
"PUT": "ПОКУПИТЬ",
|
||||
"DELETE": "УДАЛИТЬ",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "Новый ответ",
|
||||
"Triggers when there is new response": "Триггеры при новом ответе",
|
||||
"Form": "Форма",
|
||||
"Include Team Drive Forms": "Включить Team Drive Формы",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Определяет, должны ли в результаты включаться формы из Team Drive."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Receive form responses from Google Forms",
|
||||
"Custom API Call": "Custom API Call",
|
||||
"Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
|
||||
"Method": "Method",
|
||||
"Headers": "Headers",
|
||||
"Query Parameters": "Query Parameters",
|
||||
"Body": "Body",
|
||||
"Response is Binary ?": "Response is Binary ?",
|
||||
"No Error on Failure": "No Error on Failure",
|
||||
"Timeout (in seconds)": "Timeout (in seconds)",
|
||||
"Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
|
||||
"Enable for files like PDFs, images, etc..": "Enable for files like PDFs, images, etc..",
|
||||
"GET": "GET",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "DELETE",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "New Response",
|
||||
"Triggers when there is new response": "Triggers when there is new response",
|
||||
"Form": "Form",
|
||||
"Include Team Drive Forms": "Include Team Drive Forms",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determines if forms from Team Drives should be included in the results."
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"Google Forms": "Google Forms",
|
||||
"Receive form responses from Google Forms": "Receive form responses from Google Forms",
|
||||
"Custom API Call": "Custom API Call",
|
||||
"Make a custom API call to a specific endpoint": "Make a custom API call to a specific endpoint",
|
||||
"Method": "Method",
|
||||
"Headers": "Headers",
|
||||
"Query Parameters": "Query Parameters",
|
||||
"Body": "Body",
|
||||
"No Error on Failure": "No Error on Failure",
|
||||
"Timeout (in seconds)": "Timeout (in seconds)",
|
||||
"Authorization headers are injected automatically from your connection.": "Authorization headers are injected automatically from your connection.",
|
||||
"GET": "GET",
|
||||
"POST": "POST",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "PUT",
|
||||
"DELETE": "DELETE",
|
||||
"HEAD": "HEAD",
|
||||
"New Response": "New Response",
|
||||
"Triggers when there is new response": "Triggers when there is new response",
|
||||
"Form": "Form",
|
||||
"Include Team Drive Forms": "Include Team Drive Forms",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determines if forms from Team Drives should be included in the results."
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"Receive form responses from Google Forms": "Receive form responses from Google Forms",
|
||||
"Custom API Call": "自定义 API 呼叫",
|
||||
"Make a custom API call to a specific endpoint": "将一个自定义 API 调用到一个特定的终点",
|
||||
"Method": "方法",
|
||||
"Headers": "信头",
|
||||
"Query Parameters": "查询参数",
|
||||
"Body": "正文内容",
|
||||
"Response is Binary ?": "Response is Binary ?",
|
||||
"No Error on Failure": "失败时没有错误",
|
||||
"Timeout (in seconds)": "超时(秒)",
|
||||
"Authorization headers are injected automatically from your connection.": "授权头自动从您的连接中注入。",
|
||||
"Enable for files like PDFs, images, etc..": "Enable for files like PDFs, images, etc..",
|
||||
"GET": "获取",
|
||||
"POST": "帖子",
|
||||
"PATCH": "PATCH",
|
||||
"PUT": "弹出",
|
||||
"DELETE": "删除",
|
||||
"HEAD": "黑色",
|
||||
"New Response": "New Response",
|
||||
"Triggers when there is new response": "Triggers when there is new response",
|
||||
"Form": "Form",
|
||||
"Include Team Drive Forms": "Include Team Drive Forms",
|
||||
"Determines if forms from Team Drives should be included in the results.": "Determines if forms from Team Drives should be included in the results."
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { createCustomApiCallAction } from '@activepieces/pieces-common';
|
||||
import {
|
||||
OAuth2PropertyValue,
|
||||
PieceAuth,
|
||||
createPiece,
|
||||
} from '@activepieces/pieces-framework';
|
||||
import { PieceCategory } from '@activepieces/shared';
|
||||
import { newResponse } from './lib/triggers/new-form-response';
|
||||
|
||||
export const googleFormsAuth = PieceAuth.OAuth2({
|
||||
authUrl: 'https://accounts.google.com/o/oauth2/auth',
|
||||
tokenUrl: 'https://oauth2.googleapis.com/token',
|
||||
required: true,
|
||||
scope: [
|
||||
'https://www.googleapis.com/auth/forms.responses.readonly',
|
||||
'https://www.googleapis.com/auth/drive.readonly',
|
||||
],
|
||||
});
|
||||
|
||||
export const googleForms = createPiece({
|
||||
displayName: 'Google Forms',
|
||||
description: 'Receive form responses from Google Forms',
|
||||
|
||||
minimumSupportedRelease: '0.30.0',
|
||||
logoUrl: 'https://cdn.activepieces.com/pieces/google-forms.png',
|
||||
categories: [PieceCategory.FORMS_AND_SURVEYS],
|
||||
authors: ["kishanprmr","MoShizzle","khaledmashaly","abuaboud","Startouf"],
|
||||
auth: googleFormsAuth,
|
||||
actions: [
|
||||
createCustomApiCallAction({
|
||||
baseUrl: () => 'https://forms.googleapis.com/v1',
|
||||
auth: googleFormsAuth,
|
||||
authMapping: async (auth) => ({
|
||||
Authorization: `Bearer ${(auth).access_token}`,
|
||||
}),
|
||||
}),
|
||||
],
|
||||
triggers: [newResponse],
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
import { Property, OAuth2PropertyValue } from '@activepieces/pieces-framework';
|
||||
import {
|
||||
httpClient,
|
||||
HttpMethod,
|
||||
AuthenticationType,
|
||||
} from '@activepieces/pieces-common';
|
||||
import { googleFormsAuth } from '../..';
|
||||
|
||||
export const googleFormsCommon = {
|
||||
include_team_drives: Property.Checkbox({
|
||||
displayName: 'Include Team Drive Forms',
|
||||
description:
|
||||
'Determines if forms from Team Drives should be included in the results.',
|
||||
defaultValue: false,
|
||||
required: false,
|
||||
}),
|
||||
form_id: Property.Dropdown({
|
||||
displayName: 'Form',
|
||||
required: true,
|
||||
auth: googleFormsAuth,
|
||||
refreshers: ['include_team_drives'],
|
||||
options: async ({ auth, include_team_drives }) => {
|
||||
if (!auth) {
|
||||
return {
|
||||
disabled: true,
|
||||
options: [],
|
||||
placeholder: 'Please authenticate first',
|
||||
};
|
||||
}
|
||||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue;
|
||||
const files = (
|
||||
await httpClient.sendRequest<{ files: { id: string; name: string }[] }>(
|
||||
{
|
||||
method: HttpMethod.GET,
|
||||
url: `https://www.googleapis.com/drive/v3/files`,
|
||||
queryParams: {
|
||||
q: "mimeType='application/vnd.google-apps.form'",
|
||||
includeItemsFromAllDrives: include_team_drives ? 'true' : 'false',
|
||||
supportsAllDrives: 'true',
|
||||
},
|
||||
authentication: {
|
||||
type: AuthenticationType.BEARER_TOKEN,
|
||||
token: authProp['access_token'],
|
||||
},
|
||||
}
|
||||
)
|
||||
).body.files;
|
||||
return {
|
||||
disabled: false,
|
||||
options: files.map((file: { id: string; name: string }) => {
|
||||
return {
|
||||
label: file.name,
|
||||
value: file.id,
|
||||
};
|
||||
}),
|
||||
};
|
||||
},
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,137 @@
|
||||
import {
|
||||
DedupeStrategy,
|
||||
httpClient,
|
||||
HttpMethod,
|
||||
Polling,
|
||||
pollingHelper,
|
||||
} from '@activepieces/pieces-common';
|
||||
import {
|
||||
AppConnectionValueForAuthProperty,
|
||||
createTrigger,
|
||||
OAuth2PropertyValue,
|
||||
TriggerStrategy,
|
||||
} from '@activepieces/pieces-framework';
|
||||
import dayjs from 'dayjs';
|
||||
import { googleFormsCommon } from '../common/common';
|
||||
import { googleFormsAuth } from '../../';
|
||||
|
||||
export const newResponse = createTrigger({
|
||||
auth: googleFormsAuth,
|
||||
name: 'new_response',
|
||||
displayName: 'New Response',
|
||||
description: 'Triggers when there is new response',
|
||||
props: {
|
||||
form_id: googleFormsCommon.form_id,
|
||||
include_team_drives: googleFormsCommon.include_team_drives,
|
||||
},
|
||||
sampleData: {
|
||||
responseId:
|
||||
'ACYDBNhZI4SENjOwT4QIcXOhgco3JhuLftjpLspxETYljVZofOWuqH7bxKQqJWDwGw2IFqE',
|
||||
createTime: '2023-04-01T03:19:28.889Z',
|
||||
lastSubmittedTime: '2023-04-01T03:19:28.889881Z',
|
||||
answers: {
|
||||
'5bdc4001': {
|
||||
questionId: '5bdc4001',
|
||||
textAnswers: {
|
||||
answers: [
|
||||
{
|
||||
value: 'test',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
'283d759e': {
|
||||
questionId: '283d759e',
|
||||
textAnswers: {
|
||||
answers: [
|
||||
{
|
||||
value: 'نعم',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
'46f3e9cf': {
|
||||
questionId: '46f3e9cf',
|
||||
textAnswers: {
|
||||
answers: [
|
||||
{
|
||||
value: 'test',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
type: TriggerStrategy.POLLING,
|
||||
async test(ctx) {
|
||||
return await pollingHelper.test(polling, ctx);
|
||||
},
|
||||
async onEnable(ctx) {
|
||||
await pollingHelper.onEnable(polling, {
|
||||
auth: ctx.auth,
|
||||
store: ctx.store,
|
||||
propsValue: ctx.propsValue,
|
||||
});
|
||||
},
|
||||
async onDisable(ctx) {
|
||||
await pollingHelper.onDisable(polling, {
|
||||
auth: ctx.auth,
|
||||
store: ctx.store,
|
||||
propsValue: ctx.propsValue,
|
||||
});
|
||||
},
|
||||
async run(ctx) {
|
||||
return await pollingHelper.poll(polling, ctx);
|
||||
},
|
||||
});
|
||||
|
||||
const polling: Polling<AppConnectionValueForAuthProperty<typeof googleFormsAuth>, { form_id: string }> = {
|
||||
strategy: DedupeStrategy.TIMEBASED,
|
||||
items: async ({ auth, propsValue, lastFetchEpochMS }) => {
|
||||
const items = await getResponse(
|
||||
auth,
|
||||
propsValue.form_id,
|
||||
lastFetchEpochMS === 0 ? null : dayjs(lastFetchEpochMS).toISOString()
|
||||
);
|
||||
|
||||
return items
|
||||
.sort(
|
||||
(a, b) =>
|
||||
new Date(b.lastSubmittedTime).getTime() -
|
||||
new Date(a.lastSubmittedTime).getTime()
|
||||
)
|
||||
.map((item) => ({
|
||||
epochMilliSeconds: dayjs(item.lastSubmittedTime).valueOf(),
|
||||
data: item,
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
const getResponse = async (
|
||||
authentication: OAuth2PropertyValue,
|
||||
form_id: string,
|
||||
startDate: string | null
|
||||
) => {
|
||||
let filter = {};
|
||||
if (startDate) {
|
||||
filter = {
|
||||
filter: 'timestamp > ' + startDate,
|
||||
};
|
||||
}
|
||||
const response = await httpClient.sendRequest<{
|
||||
responses: { lastSubmittedTime: string }[];
|
||||
}>({
|
||||
url: `https://forms.googleapis.com/v1/forms/${form_id}/responses`,
|
||||
method: HttpMethod.GET,
|
||||
headers: {
|
||||
Authorization: `Bearer ${authentication.access_token}`,
|
||||
},
|
||||
queryParams: filter,
|
||||
});
|
||||
|
||||
const formResponses = response.body.responses;
|
||||
if (formResponses && Array.isArray(formResponses)) {
|
||||
return formResponses;
|
||||
}
|
||||
return [];
|
||||
};
|
||||
Reference in New Issue
Block a user