File tree Expand file tree Collapse file tree 5 files changed +279
-0
lines changed
components/frontapp/sources
new-message-template-created Expand file tree Collapse file tree 5 files changed +279
-0
lines changed Original file line number Diff line number Diff line change 1+ import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform" ;
2+ import frontapp from "../../frontapp.app.mjs" ;
3+
4+ export default {
5+ props : {
6+ frontapp,
7+ db : "$.service.db" ,
8+ timer : {
9+ type : "$.interface.timer" ,
10+ default : {
11+ intervalSeconds : DEFAULT_POLLING_SOURCE_TIMER_INTERVAL ,
12+ } ,
13+ } ,
14+ } ,
15+ methods : {
16+ _getSavedIds ( ) {
17+ return this . db . get ( "savedIds" ) || [ ] ;
18+ } ,
19+ _setSavedIds ( ids ) {
20+ this . db . set ( "savedIds" , ids ) ;
21+ } ,
22+ async startEvent ( maxItems ) {
23+ const savedIds = this . _getSavedIds ( ) ;
24+ const items = await this . getItems ( savedIds ) ;
25+
26+ const newIds = [ ] ;
27+ for ( const item of items ) {
28+ const id = this . getItemId ( item ) ;
29+ if ( ! savedIds . includes ( id ) ) {
30+ const meta = this . generateMeta ( item ) ;
31+ if ( maxItems === undefined || ( typeof maxItems === "number" && -- maxItems >= 0 ) ) {
32+ this . $emit ( item , meta ) ;
33+ }
34+ newIds . push ( id ) ;
35+ }
36+ }
37+
38+ if ( newIds . length > 0 ) {
39+ const ids = [
40+ ...savedIds ,
41+ ...newIds ,
42+ ] . slice ( - 100 ) ;
43+ this . _setSavedIds ( ids ) ;
44+ }
45+ } ,
46+ } ,
47+ async run ( ) {
48+ await this . startEvent ( ) ;
49+ } ,
50+ hooks : {
51+ async deploy ( ) {
52+ await this . startEvent ( 5 ) ;
53+ } ,
54+ } ,
55+ } ;
Original file line number Diff line number Diff line change 1+ import common from "../common/polling-ids.mjs" ;
2+ import sampleEmit from "./test-event.mjs" ;
3+
4+ export default {
5+ ...common ,
6+ key : "frontapp-new-conversation-created" ,
7+ name : "New Conversation Created" ,
8+ description : "Emit new event when a conversation is created. [See the documentation](https://dev.frontapp.com/reference/list-conversations)" ,
9+ version : "0.0.1" ,
10+ type : "source" ,
11+ dedupe : "unique" ,
12+ methods : {
13+ ...common . methods ,
14+ generateMeta ( conversation ) {
15+ return {
16+ id : conversation . id ,
17+ summary : `New conversation created: ${ conversation . subject } ` ,
18+ ts : conversation . created_at * 1000 ,
19+ } ;
20+ } ,
21+ getItemId ( conversation ) {
22+ return conversation . id ;
23+ } ,
24+ async getItems ( ) {
25+ const response = await this . frontapp . listConversations ( {
26+ params : {
27+ sort_by : "date" ,
28+ sort_order : "desc" ,
29+ } ,
30+ } ) ;
31+
32+ return response . _results || [ ] ;
33+ } ,
34+ } ,
35+ sampleEmit,
36+ } ;
Original file line number Diff line number Diff line change 1+ export default {
2+ "_links" : {
3+ "self" : "string" ,
4+ "related" : {
5+ "events" : "string" ,
6+ "followers" : "string" ,
7+ "messages" : "string" ,
8+ "comments" : "string" ,
9+ "inboxes" : "string" ,
10+ "last_message" : "string"
11+ }
12+ } ,
13+ "id" : "cnv_123abc" ,
14+ "subject" : "New conversation subject" ,
15+ "status" : "open" ,
16+ "assignee" : {
17+ "_links" : {
18+ "self" : "string" ,
19+ "related" : {
20+ "inboxes" : "string" ,
21+ "conversations" : "string"
22+ }
23+ } ,
24+ "id" : "tea_123abc" ,
25+ 26+ "username" : "teammate" ,
27+ "first_name" : "John" ,
28+ "last_name" : "Doe" ,
29+ "is_admin" : false ,
30+ "is_available" : true ,
31+ "is_blocked" : false ,
32+ "custom_fields" : { }
33+ } ,
34+ "recipient" : {
35+ "_links" : {
36+ "related" : {
37+ "contact" : "string"
38+ }
39+ } ,
40+ "name" : "Customer Name" ,
41+ 42+ "role" : "from"
43+ } ,
44+ "tags" : [
45+ {
46+ "_links" : {
47+ "self" : "string" ,
48+ "related" : {
49+ "conversations" : "string" ,
50+ "owner" : "string" ,
51+ "children" : "string"
52+ }
53+ } ,
54+ "id" : "tag_123abc" ,
55+ "name" : "urgent" ,
56+ "description" : "Urgent conversations" ,
57+ "highlight" : "red" ,
58+ "is_private" : false ,
59+ "is_visible_in_conversation_lists" : true ,
60+ "created_at" : 1640995200 ,
61+ "updated_at" : 1640995200
62+ }
63+ ] ,
64+ "links" : [
65+ {
66+ "_links" : {
67+ "self" : "string"
68+ } ,
69+ "id" : "link_123abc" ,
70+ "name" : "Related Ticket" ,
71+ "type" : "string" ,
72+ "external_url" : "https://example.com/ticket/123" ,
73+ "custom_fields" : { }
74+ }
75+ ] ,
76+ "custom_fields" : { } ,
77+ "created_at" : 1640995200 ,
78+ "is_private" : false ,
79+ "scheduled_reminders" : [
80+ {
81+ "_links" : {
82+ "related" : {
83+ "owner" : "string"
84+ }
85+ } ,
86+ "created_at" : 1640995200 ,
87+ "scheduled_at" : 1641081600 ,
88+ "updated_at" : 1640995200
89+ }
90+ ] ,
91+ "metadata" : {
92+ "external_conversation_ids" : [
93+ "external_123"
94+ ]
95+ }
96+ } ;
Original file line number Diff line number Diff line change 1+ import common from "../common/polling-ids.mjs" ;
2+ import sampleEmit from "./test-event.mjs" ;
3+
4+ export default {
5+ ...common ,
6+ key : "frontapp-new-message-template-created" ,
7+ name : "New Message Template Created" ,
8+ description : "Emit new event when a message template is created. [See the documentation](https://dev.frontapp.com/reference/list-message-templates)" ,
9+ version : "0.0.1" ,
10+ type : "source" ,
11+ dedupe : "unique" ,
12+ methods : {
13+ ...common . methods ,
14+ generateMeta ( template ) {
15+ return {
16+ id : template . id ,
17+ summary : `New message template created: ${ template . name } ` ,
18+ ts : template . created_at * 1000 ,
19+ } ;
20+ } ,
21+ getItemId ( template ) {
22+ return template . id ;
23+ } ,
24+ async getItems ( ) {
25+ const response = await this . frontapp . listMessageTemplates ( {
26+ params : {
27+ sort_by : "created_at" ,
28+ sort_order : "desc" ,
29+ } ,
30+ } ) ;
31+
32+ return response . _results || [ ] ;
33+ } ,
34+ } ,
35+ sampleEmit,
36+ } ;
Original file line number Diff line number Diff line change 1+ export default {
2+ "_links" : {
3+ "self" : "string" ,
4+ "related" : {
5+ "folder" : "string" ,
6+ "inboxes" : "string"
7+ }
8+ } ,
9+ "id" : "tpl_123abc" ,
10+ "name" : "Welcome Email Template" ,
11+ "subject" : "Welcome to our service!" ,
12+ "body" : "<p>Welcome to our service! We're excited to have you on board.</p><p>Best regards,<br>The Team</p>" ,
13+ "folder_id" : "fol_123abc" ,
14+ "inbox_ids" : [
15+ "inb_123abc" ,
16+ "inb_456def"
17+ ] ,
18+ "attachments" : [
19+ {
20+ "filename" : "welcome-guide.pdf" ,
21+ "url" : "string" ,
22+ "content_type" : "application/pdf" ,
23+ "size" : 1024000
24+ }
25+ ] ,
26+ "created_at" : 1640995200 ,
27+ "updated_at" : 1640995200 ,
28+ "is_available_for_all_inboxes" : false ,
29+ "folder" : {
30+ "_links" : {
31+ "self" : "string" ,
32+ "related" : {
33+ "owner" : "string"
34+ }
35+ } ,
36+ "id" : "fol_123abc" ,
37+ "name" : "Customer Onboarding" ,
38+ "description" : "Templates for customer onboarding process"
39+ } ,
40+ "inboxes" : [
41+ {
42+ "_links" : {
43+ "self" : "string" ,
44+ "related" : {
45+ "conversations" : "string" ,
46+ "teammates" : "string" ,
47+ "channels" : "string" ,
48+ "owner" : "string"
49+ }
50+ } ,
51+ "id" : "inb_123abc" ,
52+ "name" : "Support Inbox" ,
53+ "is_private" : false
54+ }
55+ ]
56+ } ;
You can’t perform that action at this time.
0 commit comments