solagent_plugin_helius/
get_webhook.rs

1// Copyright 2025 zTgx
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use serde::{Deserialize, Serialize};
16use solagent_core::SolanaAgentKit;
17
18#[derive(Debug, Serialize, Deserialize)]
19pub struct HeliusWebhookIdResponse {
20    pub wallet: String,
21    pub webhook_url: String,
22    pub transaction_types: Vec<String>,
23    pub account_addresses: Vec<String>,
24    pub webhook_type: String,
25}
26
27/// Retrieves a Helius Webhook by ID, returning only the specified fields.
28///
29/// # Arguments
30/// * `agent` - An instance of SolanaAgentKit (with .config.HELIUS_API_KEY)
31/// * `webhook_id` - The unique ID of the webhook to delete
32///
33/// # Returns
34/// A HeliusWebhook object containing { wallet, webhookURL, transactionTypes, accountAddresses, webhookType }
35pub async fn get_webhook(
36    agent: &SolanaAgentKit,
37    webhook_id: &str,
38) -> Result<HeliusWebhookIdResponse, Box<dyn std::error::Error>> {
39    // Get the Helius API key from the agent's configuration
40    let api_key = match agent.config.helius_api_key.as_ref() {
41        Some(key) => key,
42        None => return Err("Missing Helius API key in agent.config.HELIUS_API_KEY".into()),
43    };
44
45    let client = reqwest::Client::new();
46    let url = format!("https://api.helius.xyz/v0/webhooks/{}?api-key={}", webhook_id, api_key);
47
48    let response = client.get(url).header("Content-Type", "application/json").send().await?;
49
50    let data = response.json::<HeliusWebhookIdResponse>().await?;
51    Ok(data)
52}