Skip to content

Commit

Permalink
Merge pull request #386 from bettersg/develop
Browse files Browse the repository at this point in the history
3.1.2
  • Loading branch information
sarge1989 authored Jul 17, 2024
2 parents 891ddf8 + 0ef0a52 commit 0c1fc5f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ We currently have 3 environments, prod, uat, and local. The `/integration-tests`
8. The phone number to the WhatsApp User bot non-prod number is also in said zip file, in `WhatsApp.txt`. You might want to add it to your contacts for easy access.
9. Create your own Telegram bot via [botfather](https://t.me/botfather)
10. Replace `TELEGRAM_CHECKER_BOT_TOKEN` in `.secret.local` with the bot token. Note, it is `TELEGRAM_CHECKER_BOT_TOKEN` and not `TELEGRAM_BOT_TOKEN` or `TELEGRAM_WEBHOOK_TOKEN`
11. Go to botfather, navigate to the bot you created, go to "Bot Settings" > "Menu Button". Then add the cloudflare tunnel URL provided by @sarge1989 in step 7 above that routes to your localhost:5000
11. Go to botfather, type /mybots, select to the bot you created, go to > Bot Settings" > "Menu Button". Then add the cloudflare tunnel URL provided by @sarge1989 in step 7 above that routes to your localhost:5000
12. In .env.local, replace `CHECKER1_TELEGRAM_ID` and `CHECKER1_PHONE_NUMBER` with your own Telegram ID and WhatsApp Phone number respectively. Note that Whatsapp Phone number should include the country code e.g. 6591111111. Telegram ID can be obtained via this [telegram bot](https://t.me/myidbot)

### First time testing (once all above steps are done)
Expand Down
20 changes: 16 additions & 4 deletions checkers-app/src/pages/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import { signInWithToken, signOut } from "../utils/authManagement";
import { Alert, Button } from "@material-tailwind/react";
import PhoneInput from "react-phone-number-input";

function openLink(url: string) {
if (window.Telegram.WebApp) {
window.Telegram.WebApp.openLink(url);
} else {
window.open(url, "_blank");
}
}

const NameForm = ({
name,
setName,
Expand Down Expand Up @@ -67,7 +75,8 @@ const StepTwo = () => {
<br />
<a
className="underline text-checkLink"
href="https://bit.ly/checkmate-privacy"
onClick={() => openLink("https://bit.ly/checkmate-privacy")}
href="#"
>
https://bit.ly/checkmate-privacy
</a>
Expand All @@ -87,7 +96,8 @@ const StepThree = () => {
<p>
<a
className="underline text-checkLink"
href="https://bit.ly/checkmates-quiz)"
onClick={() => openLink("https://bit.ly/checkmates-quiz")}
href="#"
>
https://bit.ly/checkmates-quiz
</a>
Expand All @@ -114,7 +124,8 @@ const StepFour = () => {
<p>
<a
className="underline text-checkLink"
href="https://bit.ly/checkmates-groupchat)"
onClick={() => openLink("https://bit.ly/checkmates-groupchat")}
href="#"
>
https://bit.ly/checkmates-groupchat
</a>
Expand All @@ -128,7 +139,8 @@ const StepFour = () => {
<p>
<a
className="underline text-checkLink"
href="https://bit.ly/checkmates-wiki)"
onClick={() => openLink("https://bit.ly/checkmates-wiki")}
href="#"
>
https://bit.ly/checkmates-wiki
</a>
Expand Down
31 changes: 17 additions & 14 deletions functions/src/definitions/batchJobs/batchJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { TIME } from "../../utils/time"
import { getFullLeaderboard } from "../common/statistics"

const runtimeEnvironment = defineString(AppEnv.ENVIRONMENT)
const checkerAppHost = process.env.CHECKER_APP_HOST

if (!admin.apps.length) {
admin.initializeApp()
Expand Down Expand Up @@ -76,22 +77,24 @@ async function deactivateAndRemind() {
)
return Promise.resolve()
}
const replyMarkup = {
keyboard: [
[
{
text: "/deactivate",
},
],
],
resize_keyboard: true,
one_time_keyboard: true,
}
const replyMarkup = checkerAppHost
? {
inline_keyboard: [
[
{
text: "CheckMates' Portal↗️",
web_app: { url: checkerAppHost },
},
],
],
}
: null
const reactivationMessage = `Hello ${doc.get(
"name"
)}! Thanks for all your contributions so far🙏. We noticed that you have an outstanding message that hasn't been checked, and thought to remind you on it!
You can go to the CheckMates' Portal and find your outstanding votes there. You can opt to pass the vote there, but we hope you'll at least give it a try 💪.
If you'd like take a break, just type /deactivate. We'll stop sending you messages to vote on. Once you're ready to get back, you can type /activate to start receiving messages again.`
)}! Thanks for all your contributions so far🙏. We noticed that you haven't voted in 3 days! You're probably busy, and we don't want your votes to pile up, so we're temporarily stopped sending you messages to vote on.
To resume getting messages, just vote on any of your outstanding messages, which you can find by visiting the CheckMates' Portal. Remember, if you're busy, you can vote "pass" too!`
await doc.ref.update({ isActive: false })
return sendTelegramTextMessage(
"factChecker",
telegramId,
Expand Down
13 changes: 7 additions & 6 deletions functions/src/definitions/common/responseUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function respondToRationalisationFeedback(
const instanceSnap = await instanceRef.get()
const data = instanceSnap.data()
const from = data?.from ?? null
const responses = await getResponsesObj("user", from)
const responses = await getUserResponsesObject("user", from)
if (!data) {
functions.logger.log("Missing data in respondToRationalisationFeedback")
return
Expand Down Expand Up @@ -269,12 +269,13 @@ async function sendSatisfactionSurvey(instanceSnap: DocumentSnapshot) {
return
}
const from = data?.from ?? null
const responses = await getResponsesObj("user", from)
const isSatisfactionSurveySent = instanceSnap.get("isSatisfactionSurveySent")
const userRef = db.collection("users").doc(from)
const thresholds = await getThresholds()
const cooldown = thresholds.satisfactionSurveyCooldownDays ?? 30
const userSnap = await userRef.get()
const language = userSnap.get("language") ?? "en"
const responses = await getResponsesObj("user", language)
const lastSent = userSnap.get("satisfactionSurveyLastSent")
//check lastSent is more than cooldown days ago
let cooldownDate = new Date()
Expand Down Expand Up @@ -339,7 +340,7 @@ async function sendVotingStats(instancePath: string, isUnsureReply = false) {
const truthScore = messageSnap.get("truthScore")
const thresholds = await getThresholds()
const from = instanceSnap.get("from")
const responses = await getResponsesObj("user", from)
const responses = await getUserResponsesObject("user", from)
let truthCategory

if (validResponsesCount <= 0) {
Expand Down Expand Up @@ -427,7 +428,7 @@ async function sendRationalisation(instancePath: string) {
const instanceSnap = await instanceRef.get()
const data = instanceSnap.data()
const from = data?.from ?? null
const responses = await getResponsesObj("user", from)
const responses = await getUserResponsesObject("user", from)
try {
const messageRef = instanceRef.parent.parent
if (!data) {
Expand Down Expand Up @@ -497,7 +498,7 @@ async function sendInterimUpdate(instancePath: string) {
return
}
const from = data?.from ?? null
const responses = await getResponsesObj("user", from)
const responses = await getUserResponsesObject("user", from)
if (instanceSnap.get("isReplied")) {
await sendTextMessage(
"user",
Expand Down Expand Up @@ -609,7 +610,7 @@ async function sendInterimPrompt(instanceSnap: DocumentSnapshot) {
return
}
const from = data?.from ?? null
const responses = await getResponsesObj("user", from)
const responses = await getUserResponsesObject("user", from)
const buttons = [
{
type: "reply",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ const onVoteRequestUpdateV2 = onDocumentUpdated(
(await factCheckerDocRef.set(
{
lastVotedTimestamp: postChangeData.votedTimestamp,
isActive: true,
},
{ merge: true }
))
Expand Down

0 comments on commit 0c1fc5f

Please sign in to comment.