Created
April 12, 2022 05:00
-
-
Save abaez/53730c2c6c1019f03114ffa9e38bccea to your computer and use it in GitHub Desktop.
SavvyCal IFTTT filter to create todoist task
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
const payload = JSON.parse(MakerWebhooks.jsonEvent.JsonPayload).payload; | |
/** | |
* A user for the event | |
*/ | |
interface User { | |
author: boolean; | |
email: string; | |
displayName: string; | |
} | |
/** | |
* A map for users | |
type Users = { | |
[id: string]: User; | |
} | |
*/ | |
type Users = User[]; | |
/** | |
* An event class for savvy | |
*/ | |
class SavvyEvent { | |
readonly users: Users; | |
readonly summary: string; | |
readonly meetUrl: string; | |
readonly date: string; | |
constructor(payload: any) { | |
this.summary = this.getSummary(payload); | |
this.meetUrl = this.getMeetUrl(payload); | |
this.date = this.getDate(payload); | |
this.users = this.getUsers(payload); | |
} | |
/** | |
* set description | |
*/ | |
setDescription(): string { | |
let description: string; | |
const userList = this.users.map(user => `[${user.displayName}](mailto:${user.email})`).join(", "); | |
description = `Users joining are: ${userList}`; | |
return description; | |
} | |
/** | |
* set content | |
* @param labels an array of labels to apply. | |
*/ | |
setContent(labels: string[]): string { | |
let content: string; | |
content = `SavvyCal Meeting: [${this.summary}](${this.meetUrl}) `; | |
if (labels.length > 0) { | |
content = content + labels.map(label => `@${label}`).join(" ") | |
} | |
return content; | |
} | |
/** | |
* get users | |
*/ | |
private getUsers(payload: any): Users { | |
let joining: Users = []; | |
for (const user of payload.attendees) { | |
joining.push({ | |
displayName: user.display_name, | |
email: user.email, | |
author: user.is_organizer === true, | |
}) | |
} | |
return joining; | |
} | |
/** | |
* get summary | |
*/ | |
private getSummary(payload: any): string { | |
return payload.summary; | |
} | |
/** | |
* get meet url | |
*/ | |
private getMeetUrl(payload: any): string { | |
return payload.conferencing.join_url; | |
} | |
/** | |
* get due date | |
*/ | |
private getDate(payload: any): string { | |
return payload.start_at; | |
} | |
} | |
const savvy = new SavvyEvent(payload); | |
Todoist.createTask.setPriority("1"); | |
Todoist.createTask.setDueDate(savvy.date); | |
Todoist.createTask.setTaskDescription(savvy.setDescription()); | |
Todoist.createTask.setTaskContent(savvy.setContent(["meeting"])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment