-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
135 additions
and
29 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
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
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ import { wrap } from './sentry' | |
import { announceEvent } from './lib/telegram' | ||
import { announceEventIG } from './lib/instagram' | ||
import { getInstagramWebProfileInfo } from './lib/browser' | ||
import { renderEmail, getWeeklyData } from './lib/digest' | ||
|
||
require('dotenv').config() | ||
|
||
|
@@ -656,6 +657,88 @@ export const matchNotification = functions.firestore | |
await sendEmail(data) | ||
}) | ||
|
||
export const scheduleEmail = functions.pubsub | ||
.schedule('every monday 18:00') | ||
.timeZone('America/New_York') | ||
.onRun(async (context) => { | ||
const cityDocs = ( | ||
await firestore.collection('profiles').where('type', '==', 'City').get() | ||
).docs; | ||
const cities: any = []; | ||
for (let doc of cityDocs) { | ||
cities.push({ id: doc.id, ...doc.data() }); | ||
} | ||
let data; | ||
let recipients: any = {}; | ||
for (let city of cities) { | ||
|
||
if (!city.watch?.list) { | ||
continue; | ||
} | ||
|
||
data = await getWeeklyData(city.username); | ||
const html = await renderEmail('weekly', data); | ||
|
||
let subscribers = Object.keys(city.watch?.list); | ||
|
||
for (let subscriber of subscribers) { | ||
const profilesOfSubscriber = ( | ||
await firestore | ||
.collection('profiles') | ||
.where('username', '==', subscriber) | ||
.get() | ||
).docs; | ||
|
||
if (profilesOfSubscriber.length !== 1) { | ||
continue; | ||
} | ||
|
||
const profileId = profilesOfSubscriber[0].id; | ||
|
||
const accountDoc = await firestore | ||
.collection('accounts') | ||
.doc(profileId) | ||
.get(); | ||
|
||
if (!accountDoc.exists) { | ||
continue; | ||
} | ||
|
||
const account = accountDoc.data(); | ||
|
||
recipients[profileId] = { | ||
name:account?.name, | ||
email:account?.email | ||
} | ||
|
||
let userIds = []; | ||
userIds.push(profileId); | ||
|
||
const weeklyNewsLetter = await firestore | ||
.collection('weekly-newsletters') | ||
.add({ | ||
city: city?.username, | ||
createdAt: Date.now(), | ||
sentAt: Date.now(), | ||
scheduledAt: Date.now(), | ||
userIds: [...userIds], | ||
}); | ||
|
||
const email: any = { | ||
from: `WeDance <[email protected]>`, | ||
recipients, | ||
subject: 'Weekly Newsletter', | ||
content: html, | ||
id: weeklyNewsLetter.id, | ||
type: 'City', | ||
}; | ||
return await sendEmail(email); | ||
} | ||
} | ||
return null; | ||
}); | ||
|
||
|
||
// export const taskRunner = functions | ||
// .runWith({ memory: '2GB' }) | ||
// .pubsub.schedule('* * * * *') | ||
|
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
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
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 |
---|---|---|
|
@@ -173,4 +173,4 @@ | |
</mj-column> | ||
</mj-section> | ||
</mj-body> | ||
</mjml> | ||
</mjml> |
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 |
---|---|---|
|
@@ -667,6 +667,11 @@ | |
resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.2.tgz#6286b4c7228d58ab7866d19716f3696e03a09397" | ||
integrity sha512-Q5vtl1W5ue16D+nIaW8JWebSSraJVlK+EthKn7e7UcD4KWsaSJ8BqGPXNaPghgtcn/fhvrN17Tv8ksUsQpiplw== | ||
|
||
"@types/uuid@^9.0.1": | ||
version "9.0.1" | ||
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.1.tgz#98586dc36aee8dacc98cc396dbca8d0429647aa6" | ||
integrity sha512-rFT3ak0/2trgvp4yYZo5iKFEPsET7vKydKF+VRCxlQ9bpheehyAJH89dAkaLEq/j/RZXJIqcgsmPJKUP1Z28HA== | ||
|
||
"@types/vue@^2.0.0": | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/vue/-/vue-2.0.0.tgz#ec77b3d89591deb9ca5cb052368aa9c32be088e7" | ||
|
@@ -3494,6 +3499,11 @@ module-alias@^2.2.2: | |
resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.2.2.tgz#151cdcecc24e25739ff0aa6e51e1c5716974c0e0" | ||
integrity sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q== | ||
|
||
moment@^2.29.4: | ||
version "2.29.4" | ||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.4.tgz#3dbe052889fe7c1b2ed966fcb3a77328964ef108" | ||
integrity sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w== | ||
|
||
[email protected]: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" | ||
|