solagent_plugin_cookie/
lib.rs1use serde_json::Value;
2use solagent_core::SolanaAgentKit;
3use std::error::Error;
4
5pub async fn get_agent_by_ca(
17 agent: &SolanaAgentKit,
18 contract_address: &str,
19 interval: Option<u32>,
20) -> Result<Value, Box<dyn Error>> {
21 let api_key = match agent.config.cookie_api_key.as_ref() {
23 Some(key) => key,
24 None => return Err("Missing Cookie API key in agent.config.cookie_api_key".into()),
25 };
26
27 let api_url = "https://api.cookie.fun/v2/agents/contractAddress";
28 let url = format!("{}/{}?interval=_{}Days", api_url, contract_address, interval.unwrap_or(7));
29 let client = reqwest::Client::new();
30
31 let response = client.get(&url).header("x-api-key", api_key).send().await?;
32
33 let json: Value = response.json().await?;
34 Ok(json)
35}
36
37pub async fn get_agent_by_name(
49 agent: &SolanaAgentKit,
50 twitter_name: &str,
51 interval: Option<u32>,
52) -> Result<Value, Box<dyn Error>> {
53 let api_key = match agent.config.cookie_api_key.as_ref() {
55 Some(key) => key,
56 None => return Err("Missing Cookie API key in agent.config.cookie_api_key".into()),
57 };
58
59 let api_url = "https://api.cookie.fun/v2/agents/twitterUsername";
60 let url = format!("{}/{}?interval=_{}Days", api_url, twitter_name, interval.unwrap_or(7));
61 let client = reqwest::Client::new();
62
63 let response = client.get(&url).header("x-api-key", api_key).send().await?;
64
65 let json: Value = response.json().await?;
66 Ok(json)
67}
68
69pub async fn search_tweets(
82 agent: &SolanaAgentKit,
83 tweets: &str,
84 from: &str,
85 to: &str,
86) -> Result<Value, Box<dyn Error>> {
87 let api_key = match agent.config.cookie_api_key.as_ref() {
89 Some(key) => key,
90 None => return Err("Missing Cookie API key in agent.config.cookie_api_key".into()),
91 };
92
93 let api_url = "https://api.cookie.fun/v1/hackathon/search";
94 let url = format!("{}/{}?from={}&to={}", api_url, tweets, from, to);
95 let client = reqwest::Client::new();
96
97 let response = client.get(&url).header("x-api-key", api_key).send().await?;
98
99 let json: Value = response.json().await?;
100 Ok(json)
101}