From 0ad71cbe1d2bc4be5263617d6d249a4c83d9ca5f Mon Sep 17 00:00:00 2001 From: Raazi Muhammed K Date: Sun, 7 Jul 2024 12:23:10 +0530 Subject: [PATCH 1/2] docs: create spelling bee integration proposal --- CRIP/CRIP-Spelling-bee.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 CRIP/CRIP-Spelling-bee.md diff --git a/CRIP/CRIP-Spelling-bee.md b/CRIP/CRIP-Spelling-bee.md new file mode 100644 index 0000000..fb1ad62 --- /dev/null +++ b/CRIP/CRIP-Spelling-bee.md @@ -0,0 +1,26 @@ +| proposal | title | description | author | discussions-to | status | type | category | created | requires | +| ----------------- | ------------------------ | ---------------------------------------------------- | ------------------------------------ | -------------- | ------ | ----------- | -------- | ---------- | -------- | +| CRIP-Spelling-bee | Spelling Bee Integration | Integration with Spelling Bee to validate user stats | Raazi Muhammed | | Draft | Integration | CRIP | 2024-07-07 | | + +## Title + +Spelling Bee Integration + +## Introduction + +This proposal outlines the integration of daily puzzles into the Catoff platform for the Catoff-Reclaim integration project. The integration aims to track and validate user progress on daily puzzles, including metrics such as total words found, pangrams discovered, longest word, and the center letter used. This data will be utilized to enhance user engagement and provide interactive challenges based on daily puzzle achievements. + +## External APIs Needed + +- None + +## Use Cases + +1. **Challenge Participation**: Enable users to participate in challenges that require proof of daily puzzle completion and achievements. +2. **Longest Word Challenge**: Users must find the longest possible word in the daily puzzle to complete the challenge, leveraging the center letter provided. +3. **Pangram Hunt**: Users are challenged to discover pangrams (words using every letter at least once) within the daily puzzle. + +## Data Provider + +- **Name**: Spelling Bee Stats +- **Hash Value**: 0x4a38917946919df457dab21b2b5cc927ea8a04dfb35c98833dce4c0a3b66eccb From b59ce2eef1cc5d173f99d614e87b10fadfa3469c Mon Sep 17 00:00:00 2001 From: Raazi Muhammed K Date: Sun, 7 Jul 2024 15:15:11 +0530 Subject: [PATCH 2/2] feat: integrate spelling bee with catoff, add code snippet in proposal --- .env.example | 1 + CRIP/CRIP-Spelling-bee.md | 36 ++++++++++++++++++++++++++++++ index.js | 1 + src/services/reclaimService.js | 4 ++++ src/services/spellingBeeService.js | 27 ++++++++++++++++++++++ src/utils/constants.js | 2 ++ 6 files changed, 71 insertions(+) create mode 100644 src/services/spellingBeeService.js diff --git a/.env.example b/.env.example index 2494daa..d1df196 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ TWITTER_ANALYTICS_VIEWS_SECRET=your-twitter-secret GITHUB_ACCOUNT_VERIFICATION_SECRET=your-github-secret RECLAIM_GITHUB_TOKEN=your-github-token +SPELLING_BEE_STATS_SECRET=your-spelling-bee-token diff --git a/CRIP/CRIP-Spelling-bee.md b/CRIP/CRIP-Spelling-bee.md index fb1ad62..f52064d 100644 --- a/CRIP/CRIP-Spelling-bee.md +++ b/CRIP/CRIP-Spelling-bee.md @@ -24,3 +24,39 @@ This proposal outlines the integration of daily puzzles into the Catoff platform - **Name**: Spelling Bee Stats - **Hash Value**: 0x4a38917946919df457dab21b2b5cc927ea8a04dfb35c98833dce4c0a3b66eccb + +## Code Snippet + +Below is a code snippet that demonstrates the key parts of the Spelling Bee integration. + +**`services/spellingBeeService.js`** + +```javascript +const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse') + +exports.processSpellingBeeData = async (proof, providerName) => { + const userStatsExtracted = JSON.parse( + proof[0].claimData.context + ).extractedParameters + + const userStats = { + longestWord: userStatsExtracted.longest_word, + puzzlesStarted: userStatsExtracted.puzzles_started, + totalPangrams: userStatsExtracted.total_pangrams, + totalWords: userStatsExtracted.total_words, + } + + const lastUpdateTimeStamp = JSON.parse(proof[0].claimData.timestampS) + + // Spelling bee does not provider username + const username = userStatsExtracted.user_id + + return new ReclaimServiceResponse( + providerName, + lastUpdateTimeStamp, + username, + userStats, + proof[0] + ) +} +``` diff --git a/index.js b/index.js index df7fba0..4720a0a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ const express = require('express') const bodyParser = require('body-parser') const reclaimController = require('./src/controllers/reclaimController') +require('dotenv').config() const app = express() app.use(bodyParser.json()) diff --git a/src/services/reclaimService.js b/src/services/reclaimService.js index b33006f..9ed2234 100644 --- a/src/services/reclaimService.js +++ b/src/services/reclaimService.js @@ -3,6 +3,7 @@ const { Reclaim } = require('@reclaimprotocol/js-sdk') const { RECLAIM_PROVIDER_ID, RECLAIM_APP_ID } = require('../utils/constants') const { processTwitterData } = require('./twitterService') const { processGitHubData } = require('./githubService') +const { processSpellingBeeData } = require('./spellingBeeService') exports.signWithProviderID = async (userId, providerId) => { const providerName = RECLAIM_PROVIDER_ID[providerId] @@ -49,6 +50,9 @@ const handleReclaimSession = async (userId, reclaimClient, providerName) => { case 'GITHUB_ACCOUNT_VERIFICATION': processedData = await processGitHubData(proof, providerName) break + case 'SPELLING_BEE_STATS': + processedData = await processSpellingBeeData(proof, providerName) + break default: throw new Error(`No handler for provider: ${providerName}`) } diff --git a/src/services/spellingBeeService.js b/src/services/spellingBeeService.js new file mode 100644 index 0000000..45f9a8c --- /dev/null +++ b/src/services/spellingBeeService.js @@ -0,0 +1,27 @@ +const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse') + +exports.processSpellingBeeData = async (proof, providerName) => { + const userStatsExtracted = JSON.parse( + proof[0].claimData.context + ).extractedParameters + + const userStats = { + longestWord: userStatsExtracted.longest_word, + puzzlesStarted: userStatsExtracted.puzzles_started, + totalPangrams: userStatsExtracted.total_pangrams, + totalWords: userStatsExtracted.total_words, + } + + const lastUpdateTimeStamp = JSON.parse(proof[0].claimData.timestampS) + + // Spelling bee does not provider username + const username = userStatsExtracted.user_id + + return new ReclaimServiceResponse( + providerName, + lastUpdateTimeStamp, + username, + userStats, + proof[0] + ) +} diff --git a/src/utils/constants.js b/src/utils/constants.js index 1c58669..ce34391 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -1,9 +1,11 @@ exports.RECLAIM_PROVIDER_ID = { twitter: 'TWITTER_ANALYTICS_VIEWS', github: 'GITHUB_ACCOUNT_VERIFICATION', + '6ef3c828-dc69-4ea7-bdf3-7cca065306c8': 'SPELLING_BEE_STATS', } exports.RECLAIM_APP_ID = { TWITTER_ANALYTICS_VIEWS: 'your-twitter-app-id', GITHUB_ACCOUNT_VERIFICATION: 'your-github-app-id', + SPELLING_BEE_STATS: '0x6f1aC97bbFf12558f251A11A6623C146300bF56C', }