-
-
Save kkemple/427250dc3e53e10bade77fd640259255 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// To use any npm package, just import it | |
// import axios from "axios" | |
import striptags from "striptags" | |
export default defineComponent({ | |
async run({ steps, $ }) { | |
const description = striptags(steps.trigger.event.description, ['br']).replace(/<br>/g, '\n') | |
const eventTypeMatch = description.match(/Event\sName:\s(\w+)/) | |
const zoomLink = description.match(/(https:\/\/(?:[\w-]+\.)?zoom.us\/j\/\d+\?pwd=\w+)/) | |
const eventType = eventTypeMatch ? eventTypeMatch[1] : "Meeting" | |
const attendee_emails = steps.trigger.event.attendee_emails | |
const attendees = attendee_emails === "" ? [] : attendee_emails.split(",").filter(email => email !== "[email protected]") | |
let emoji; | |
switch(eventType) { | |
case "Tea": { | |
emoji = "🍵" | |
break | |
} | |
case "Chat": { | |
emoji ="💬" | |
break | |
} | |
case "Discovery": { | |
emoji = "🧭" | |
break | |
} | |
case "Discussion": { | |
emoji = "🧠" | |
break | |
} | |
case "Initial Consultation": { | |
emoji = "💼" | |
break | |
} | |
default: { | |
emoji = "📅" | |
break | |
} | |
} | |
const meetingLink = zoomLink ? zoomLink[0] : steps.trigger.event.hangoutLink | |
const data = { | |
attendees, | |
emoji, | |
eventType, | |
gcalLink: steps.trigger.event.htmlLink, | |
organizer: steps.trigger.event.organizer__self === "True", | |
title: steps.trigger.event.summary, | |
startDate: steps.trigger.event.start__dateTime, | |
endDate: steps.trigger.event.end__dateTime, | |
} | |
if (meetingLink) { | |
data.meetingLink = meetingLink | |
} | |
if (description !== "") { | |
console.log(description) | |
data.description = description | |
} | |
return data | |
}, | |
}) |
This file contains hidden or 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
module.exports = defineComponent({ | |
props: { | |
notion: { | |
type: "app", | |
app: "notion", | |
} | |
}, | |
async run({steps, $}) { | |
if (!steps.notion_lookup.$return_value) { | |
console.log('No Notion document found!') | |
return | |
} | |
try { | |
return await require("@pipedreamhq/platform").axios(this, { | |
url: `https://api.notion.com/v1/pages/${steps.notion_lookup.$return_value.id}`, | |
headers: { | |
Authorization: `Bearer ${this.notion.$auth.oauth_access_token}`, | |
"Notion-Version": `2021-08-16`, | |
}, | |
method: "PATCH", | |
data: { | |
archived: true | |
} | |
}) | |
} catch(error) { | |
console.log(error) | |
throw error; | |
} | |
}, | |
}) |
This file contains hidden or 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
module.exports = defineComponent({ | |
props: { | |
notion: { | |
type: "app", | |
app: "notion", | |
} | |
}, | |
async run({steps, $}) { | |
try { | |
const entry = await require("@pipedreamhq/platform").axios(this, { | |
url: `https://api.notion.com/v1/databases/e2eaca20d1b14515a81f2151c03c3304/query`, | |
headers: { | |
Authorization: `Bearer ${this.notion.$auth.oauth_access_token}`, | |
"Notion-Version": `2021-08-16`, | |
}, | |
method: "POST", | |
data: { | |
filter: { | |
or: [ | |
{ | |
property: 'Gcal ID', | |
text: { | |
equals: steps.trigger.event.id | |
} | |
} | |
] | |
}, | |
} | |
}) | |
return entry.results[0]; | |
} catch(error) { | |
console.log(error) | |
throw error; | |
} | |
}, | |
}) |
This file contains hidden or 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
module.exports = defineComponent({ | |
props: { | |
notion: { | |
type: "app", | |
app: "notion", | |
} | |
}, | |
async run({steps, $}) { | |
const createPage = async () => { | |
const data = { | |
parent: { | |
database_id: "e2eaca20d1b14515a81f2151c03c3304" | |
}, | |
icon: { | |
type: "emoji", | |
emoji: steps.ETL.$return_value.emoji | |
}, | |
children: steps.ETL.$return_value.descrption ? [ | |
{ | |
object: 'block', | |
type: 'paragraph', | |
paragraph: { | |
text: [ | |
{ | |
type: 'text', | |
text: { | |
content: steps.ETL.$return_value.description, | |
}, | |
}, | |
], | |
}, | |
} | |
] : [], | |
properties: { | |
Name: { | |
title: [ | |
{ | |
text: { | |
content: steps.ETL.$return_value.title | |
} | |
} | |
] | |
}, | |
"Organizer": { | |
type: "checkbox", | |
checkbox: steps.ETL.$return_value.organizer | |
}, | |
"Calendar URL": { | |
type: "url", | |
url: steps.ETL.$return_value.gcalLink | |
}, | |
Date: { | |
type: "date", | |
date: { | |
start: steps.ETL.$return_value.startDate, | |
end: steps.ETL.$return_value.endDate | |
} | |
}, | |
"Gcal ID": { | |
rich_text: [ | |
{ | |
text: { | |
content: steps.trigger.event.id, | |
}, | |
}, | |
] | |
} | |
} | |
} | |
if (steps.ETL.$return_value.meetingLink) { | |
data.properties = { | |
...data.properties, | |
"Meeting URL": { | |
type: "url", | |
url: steps.ETL.$return_value.meetingLink | |
} | |
} | |
} | |
return await require("@pipedreamhq/platform").axios(this, { | |
url: `https://api.notion.com/v1/pages`, | |
headers: { | |
Authorization: `Bearer ${this.notion.$auth.oauth_access_token}`, | |
"Notion-Version": `2021-08-16`, | |
}, | |
method: "POST", | |
data | |
}) | |
} | |
const updatePage = async () => { | |
return await require("@pipedreamhq/platform").axios(this, { | |
url: `https://api.notion.com/v1/pages/${steps.notion_lookup.$return_value.id}`, | |
headers: { | |
Authorization: `Bearer ${this.notion.$auth.oauth_access_token}`, | |
"Notion-Version": `2021-08-16`, | |
}, | |
method: "PATCH", | |
data: { | |
properties: { | |
Name: { | |
title: [ | |
{ | |
text: { | |
content: steps.ETL.$return_value.title | |
} | |
} | |
] | |
}, | |
Date: { | |
type: "date", | |
date: { | |
start: steps.ETL.$return_value.startDate, | |
end: steps.ETL.$return_value.endDate | |
} | |
} | |
} | |
} | |
}) | |
} | |
try { | |
if (steps.notion_lookup.$return_value) { | |
return await updatePage(); | |
} else { | |
return await createPage(); | |
} | |
} catch (error) { | |
console.log(error); | |
throw error; | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment