CatoffGaming / catoff-reclaim-integration-proposal

Welcome to the Catoff-Reclaim Integration Open Source Project!
https://game.catoff.xyz
15 stars 51 forks source link

proposal - Twitter Hashtag Likes Verification - Integration to verify likes on tweets with a specific hashtag #49

Open ritunk opened 2 months ago

ritunk commented 2 months ago
proposal title description author discussions-to status type category created requires
001 Tweet Likes Verification Service Integration to verify the number of likes on a tweet with a specific hashtag Ritik Raj ritikraj8654@gmail.com Draft Integration CRIP 2024-07-11

Title

Tweet Likes Verification Service

Introduction

This proposal aims to introduce an integration that verifies the number of likes on a tweet containing a specific hashtag. This service will allow users to link their Twitter accounts and retrieve the number of likes on their tweets with specified hashtags. This feature enhances our application by providing users with deeper insights into the engagement their tweets receive based on specific topics.

External APIs Needed

Twitter API Reclaim API

Use Cases

Marketing Analysis: Marketers can track the performance of their campaigns by monitoring likes on tweets with campaign-specific hashtags. Content Creators: Influencers and content creators can measure the engagement of their posts related to particular topics or trends. Research: Researchers can analyze public sentiment and engagement on tweets associated with specific hashtags.

Data Provider

Name: Twitter Hash Value:

Code Snippet

utils/constants.js exports.RECLAIM_PROVIDER_ID = { twitter: 'TWITTER_ANALYTICS_VIEWS', github: 'GITHUB_ACCOUNT_VERIFICATION', tweetLikes: 'TWEET_LIKES_VERIFICATION', // Added for the new service }

exports.RECLAIM_APP_ID = { TWITTER_ANALYTICS_VIEWS: 'your-twitter-app-id', GITHUB_ACCOUNT_VERIFICATION: 'your-github-app-id', TWEET_LIKES_VERIFICATION: 'your-tweet-likes-app-id', // Added for the new service }

services/reclaimService.js

const axios = require('axios') 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 { processTweetLikesData } = require('./tweetLikesService') // Import the new service

exports.signWithProviderID = async (userId, providerId) => { const providerName = RECLAIM_PROVIDER_ID[providerId] const reclaimAppID = RECLAIM_APP_ID[providerName] const reclaimAppSecret = process.env[${providerName}_SECRET]

console.log( Sending signature request to Reclaim for userId: ${userId} with providerName: ${providerName} )

try { const reclaimClient = new Reclaim.ProofRequest(reclaimAppID) await reclaimClient.buildProofRequest(providerId) reclaimClient.setSignature( await reclaimClient.generateSignature(reclaimAppSecret) ) const { requestUrl: signedUrl } = await reclaimClient.createVerificationRequest()

await handleReclaimSession(userId, reclaimClient, providerName)
return signedUrl

} catch (error) { console.error( Failed to process Reclaim request for userId: ${userId}, error ) throw error } }

const handleReclaimSession = async (userId, reclaimClient, providerName) => { await reclaimClient.startSession({ onSuccessCallback: async proof => { console.log( Successful reclaim callback with proof: ${JSON.stringify(proof)} )

  try {
    let processedData
    switch (providerName) {
      case 'TWITTER_ANALYTICS_VIEWS':
        processedData = await processTwitterData(proof, providerName)
        break
      case 'GITHUB_ACCOUNT_VERIFICATION':
        processedData = await processGitHubData(proof, providerName)
        break
      case 'TWEET_LIKES_VERIFICATION':  // Handle the new service
        processedData = await processTweetLikesData(proof, providerName)
        break
      default:
        throw new Error(`No handler for provider: ${providerName}`)
    }

    console.log(`Processed data: ${JSON.stringify(processedData)}`)
  } catch (error) {
    console.error(
      `Failed to process Reclaim proof for userId: ${userId}`,
      error
    )
  }
},
onFailureCallback: error => {
  console.error(`Verification failed for userId: ${userId}`, error)
},

}) }

services/tweetLikesService.js

const { ReclaimServiceResponse } = require('../utils/reclaimServiceResponse')

exports.processTweetLikesData = async (proof, providerName) => { // Extract relevant data from the proof const tweetData = JSON.parse(proof[0].claimData.context).extractedParameters const tweetLikes = tweetData.likes const tweetHashtag = tweetData.hashtag const tweetId = tweetData.tweetId

// Process the extracted data const tweetLikesValue = tweetLikes.match(/likes=\"([\d,]+)/)[1].replace(/,/g, '')

// Extract additional relevant data from the proof const url = JSON.parse(proof[0].claimData.parameters).url const matchurl = url.match(/user\/([^\/]+)/) const username = matchurl ? matchurl[1] : null const lastUpdateTimeStamp = JSON.parse(proof[0].claimData.timestampS)

// Create a ReclaimServiceResponse object with the processed data

return new ReclaimServiceResponse( providerName, lastUpdateTimeStamp, username, parseInt(tweetLikesValue, 10), proof[0] ) }

utils/reclaimServiceResponse.js

class ReclaimServiceResponse { constructor(flag, timestamp, userName, targetValue, data) { this.flag = flag this.timestamp = timestamp this.userName = userName this.targetValue = targetValue this.data = data } }

module.exports = { ReclaimServiceResponse }