Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4642 from thirstycode/main
feat(poper): New Lead Trigger
- Loading branch information
Showing
9 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"extends": [ | ||
"../../../../.eslintrc.base.json" | ||
], | ||
"ignorePatterns": [ | ||
"!**/*" | ||
], | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx", | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.ts", | ||
"*.tsx" | ||
], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": [ | ||
"*.js", | ||
"*.jsx" | ||
], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# pieces-poper | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Building | ||
|
||
Run `nx build pieces-poper` to build the library. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-poper", | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "pieces-poper", | ||
"$schema": "../../../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/pieces/community/poper/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "@nx/js:tsc", | ||
"outputs": [ | ||
"{options.outputPath}" | ||
], | ||
"options": { | ||
"outputPath": "dist/packages/pieces/community/poper", | ||
"tsConfig": "packages/pieces/community/poper/tsconfig.lib.json", | ||
"packageJson": "packages/pieces/community/poper/package.json", | ||
"main": "packages/pieces/community/poper/src/index.ts", | ||
"assets": [ | ||
"packages/pieces/community/poper/*.md" | ||
], | ||
"buildableProjectDepsInPackageJsonType": "dependencies", | ||
"updateBuildableProjectDepsInPackageJson": true | ||
} | ||
}, | ||
"publish": { | ||
"command": "node tools/scripts/publish.mjs pieces-poper {args.ver} {args.tag}", | ||
"dependsOn": [ | ||
"build" | ||
] | ||
}, | ||
"lint": { | ||
"executor": "@nx/eslint:lint", | ||
"outputs": [ | ||
"{options.outputFile}" | ||
] | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { createPiece, PieceAuth } from '@activepieces/pieces-framework'; | ||
import { newLead } from './lib/triggers/new-lead'; | ||
import { HttpMethod, HttpRequest, httpClient } from '@activepieces/pieces-common'; | ||
import { PieceCategory } from '@activepieces/shared'; | ||
|
||
export const poperAuth = PieceAuth.SecretText({ | ||
displayName: 'API Key', | ||
description: | ||
'Use the Poper API key to authenticate the piece. You can find your API key in the Poper settings.', | ||
required: true, | ||
validate: async ({ auth }) => { | ||
const request: HttpRequest = { | ||
method: HttpMethod.POST, | ||
url: 'https://api.poper.ai/general/v1/ping', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: { | ||
api_key: auth, | ||
}, | ||
}; | ||
|
||
try { | ||
const res = await httpClient.sendRequest(request); | ||
|
||
if (res.status === 200) { | ||
return { | ||
valid: true, | ||
}; | ||
} | ||
|
||
return { | ||
valid: false, | ||
error: 'API Key is invalid', | ||
}; | ||
} catch (e) { | ||
return { | ||
valid: false, | ||
error: 'API Key is invalid', | ||
}; | ||
} | ||
}, | ||
}); | ||
|
||
export const poper = createPiece({ | ||
displayName: 'Poper', | ||
auth: poperAuth, | ||
minimumSupportedRelease: '0.20.0', | ||
categories: [PieceCategory.MARKETING], | ||
description: | ||
'AI Driven Pop-up Builder that can convert visitors into customers,increase subscriber count, and skyrocket sales.', | ||
logoUrl: 'https://cdn.activepieces.com/pieces/poper.png', | ||
authors: ['thirstycode'], | ||
actions: [], | ||
triggers: [newLead], | ||
}); |
143 changes: 143 additions & 0 deletions
143
packages/pieces/community/poper/src/lib/triggers/new-lead.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
|
||
import { createTrigger, TriggerStrategy, PiecePropValueSchema, StaticPropsValue, DropdownProperty } from '@activepieces/pieces-framework'; | ||
import { DedupeStrategy, Polling, pollingHelper, HttpMethod, HttpRequest, httpClient } from '@activepieces/pieces-common'; | ||
import { poperAuth } from './../../'; | ||
|
||
import { Property } from '@activepieces/pieces-framework'; | ||
|
||
const buildEmptyList = ({ placeholder }: { placeholder: string }) => { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder, | ||
}; | ||
}; | ||
|
||
const popupsDropdown = Property.Dropdown<string>({ | ||
displayName: 'Popup Name', | ||
refreshers: [], | ||
description: "Select the popup name to trigger the action", | ||
required: true, | ||
options: async ({ auth }) => { | ||
if (!auth) { | ||
return buildEmptyList({ | ||
placeholder: 'Please select an authentication', | ||
}); | ||
} | ||
|
||
const request: HttpRequest = { | ||
method: HttpMethod.POST, | ||
url: 'https://api.poper.ai/general/v1/popup/list', | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: { | ||
api_key: auth, | ||
} | ||
}; | ||
|
||
try{ | ||
|
||
const res = await httpClient.sendRequest(request); | ||
|
||
if(res.status === 200){ | ||
const popups = res.body.popups; | ||
if (popups.length === 0) { | ||
return buildEmptyList({ | ||
placeholder: 'No popups found! Please create a popup.', | ||
}); | ||
} | ||
|
||
const options = popups.map((p:any) => ({ | ||
label: p.name, | ||
value: p.id, | ||
})); | ||
|
||
return { | ||
disabled: false, | ||
options, | ||
}; | ||
} | ||
|
||
return buildEmptyList({ | ||
placeholder: 'Not authorized.', | ||
}); | ||
} catch(e){ | ||
return buildEmptyList({ | ||
placeholder: 'Not authorized.', | ||
}); | ||
} | ||
|
||
}, | ||
}); | ||
|
||
// replace auth with piece auth variable | ||
const polling: Polling< PiecePropValueSchema<typeof poperAuth>, StaticPropsValue<{ popup_id: DropdownProperty<string, false> | DropdownProperty<string, true>; }> > = { | ||
strategy: DedupeStrategy.LAST_ITEM, | ||
items: async ({ auth, propsValue }) => { | ||
// implement the logic to fetch the items | ||
const request: HttpRequest = { | ||
method: HttpMethod.POST, | ||
url: 'https://api.poper.ai/general/v1/popup/responses', | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
body: { | ||
api_key: auth, | ||
popup_id: propsValue.popup_id, | ||
} | ||
}; | ||
|
||
try{ | ||
|
||
const res = await httpClient.sendRequest(request); | ||
|
||
if(res.status === 200){ | ||
const responses = res.body.responses; | ||
if (responses.length === 0) { | ||
return []; | ||
} | ||
|
||
return responses.map((response:any) => ({ | ||
id: response.id, | ||
data: response, | ||
})); | ||
} | ||
|
||
return []; | ||
} catch(e){ | ||
return []; | ||
} | ||
}, | ||
|
||
} | ||
|
||
export const newLead = createTrigger({ | ||
auth: poperAuth, | ||
name: 'newLead', | ||
displayName: 'New Lead', | ||
description: 'Triggers when a new lead is obtained from popup', | ||
props: { | ||
popup_id: popupsDropdown, | ||
}, | ||
sampleData: {}, | ||
type: TriggerStrategy.POLLING, | ||
async test(context) { | ||
const { store, auth, propsValue } = context; | ||
return await pollingHelper.test(polling, { store, auth, propsValue }); | ||
}, | ||
async onEnable(context) { | ||
const { store, auth, propsValue } = context; | ||
await pollingHelper.onEnable(polling, { store, auth, propsValue }); | ||
}, | ||
|
||
async onDisable(context) { | ||
const { store, auth, propsValue } = context; | ||
await pollingHelper.onDisable(polling, { store, auth, propsValue }); | ||
}, | ||
|
||
async run(context) { | ||
const { store, auth, propsValue } = context; | ||
return await pollingHelper.poll(polling, { store, auth, propsValue }); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": "../../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitOverride": true, | ||
"noPropertyAccessFromIndexSignature": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "../../../../dist/out-tsc", | ||
"declaration": true, | ||
"types": ["node"] | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters