-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/charity #852
Fix/charity #852
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "@ai16z/client-whatsapp", | ||
"version": "0.0.1", | ||
"description": "WhatsApp client for Eliza", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsc", | ||
"clean": "rimraf dist", | ||
"test": "jest", | ||
"lint": "eslint src --ext .ts" | ||
}, | ||
"dependencies": { | ||
"@ai16z/eliza": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.0.0", | ||
"typescript": "^5.0.0", | ||
"rimraf": "^5.0.0", | ||
"jest": "^29.0.0", | ||
"@types/jest": "^29.0.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IAgentRuntime } from "@ai16z/eliza"; | ||
|
||
export async function validateWhatsAppConfig( | ||
runtime: IAgentRuntime | ||
): Promise<void> { | ||
const requiredSettings = [ | ||
"WHATSAPP_API_TOKEN", | ||
"WHATSAPP_PHONE_NUMBER_ID", | ||
"WHATSAPP_APP_ID", | ||
"WHATSAPP_APP_SECRET", | ||
"WHATSAPP_WEBHOOK_VERIFY_TOKEN" | ||
]; | ||
|
||
for (const setting of requiredSettings) { | ||
if (!runtime.getSetting(setting)) { | ||
throw new Error( | ||
`Missing required WhatsApp configuration: ${setting}` | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { elizaLogger } from "@ai16z/eliza"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why these whatsapp changes are included There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like upstream changes from before idk |
||
import { Client, IAgentRuntime } from "@ai16z/eliza"; | ||
import { WhatsAppClient } from "./whatsappClient"; | ||
import { validateWhatsAppConfig } from "../../../eliza/packages/client-whatsapp/src/environment"; | ||
|
||
export const WhatsAppClientInterface: Client = { | ||
start: async (runtime: IAgentRuntime) => { | ||
await validateWhatsAppConfig(runtime); | ||
|
||
const client = new WhatsAppClient( | ||
runtime, | ||
runtime.getSetting("WHATSAPP_API_TOKEN"), | ||
runtime.getSetting("WHATSAPP_PHONE_NUMBER_ID") | ||
); | ||
|
||
await client.start(); | ||
|
||
elizaLogger.success( | ||
`✅ WhatsApp client successfully started for character ${runtime.character.name}` | ||
); | ||
return client; | ||
}, | ||
stop: async (runtime: IAgentRuntime) => { | ||
elizaLogger.warn("WhatsApp client stopping..."); | ||
}, | ||
}; | ||
|
||
export default WhatsAppClientInterface; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,22 +380,24 @@ export async function executeTransfer(wallet: Wallet, amount: number, sourceAsse | |
|
||
/** | ||
* Gets the charity address based on the network. | ||
* For now we are giving to the following charity, but will make this configurable in the future | ||
* https://www.givedirectly.org/crypto/?_gl=1*va5e6k*_gcl_au*MTM1NDUzNTk5Mi4xNzMzMDczNjA3*_ga*OTIwMDMwNTMwLjE3MzMwNzM2MDg.*_ga_GV8XF9FJ16*MTczMzA3MzYwNy4xLjEuMTczMzA3MzYyMi40NS4wLjA. | ||
* @param {string} network - The network to use. | ||
* @param {boolean} isCharitable - Whether charity donations are enabled | ||
* @throws {Error} If charity address for the network is not configured when charity is enabled | ||
*/ | ||
export function getCharityAddress(network: string): string { | ||
let charityAddress; | ||
if (network === "base") { | ||
charityAddress = "0x1234567890123456789012345678901234567890"; | ||
} else if (network === "sol") { | ||
charityAddress = "pWvDXKu6CpbKKvKQkZvDA66hgsTB6X2AgFxksYogHLV"; | ||
} else if (network === "eth") { | ||
charityAddress = "0x750EF1D7a0b4Ab1c97B7A623D7917CcEb5ea779C"; | ||
} else if (network === "arb") { | ||
charityAddress = "0x1234567890123456789012345678901234567890"; | ||
} else if (network === "pol") { | ||
charityAddress = "0x1234567890123456789012345678901234567890"; | ||
export function getCharityAddress(network: string, isCharitable: boolean = false): string | null { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will also want to handle what happens when getCharityAddress returns null. I had some changes here for that feel free to take a look and integrate: f7ace73 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its a consensus of the group to have charitble as a boolean set to false |
||
// Check both environment variable and passed parameter | ||
const isCharityEnabled = process.env.IS_CHARITABLE === 'true' && isCharitable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's funny because I was about to make this nullable :) Great minds! |
||
|
||
Comment on lines
+389
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use runtime.getSetting instead of this check thanks :) |
||
if (!isCharityEnabled) { | ||
return null; | ||
} | ||
|
||
const networkKey = `CHARITY_ADDRESS_${network.toUpperCase()}`; | ||
const charityAddress = process.env[networkKey]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here :) |
||
|
||
if (!charityAddress) { | ||
throw new Error(`Charity address not configured for network ${network}. Please set ${networkKey} in your environment variables.`); | ||
} | ||
|
||
return charityAddress; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update the BASE address to the ETH address they should be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And arb and poly should be empty for now as they are dummy addresses atm :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're removing hardcoded wallets its weird to force projects to give charity