1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//! Types and methods for managing wit intents
use crate::{
client::WitClient,
common_types::{DeleteResponse, EntityBasic, IntentBasic},
errors::Error,
};
use reqwest::Method;
use serde::Deserialize;
use serde_json::{json, Value};
/// The response received when fetching an intent
#[derive(Debug, Deserialize, PartialEq)]
pub struct IntentResponse {
/// The id of the intent
pub id: String,
/// The name of the intent
pub name: String,
/// Entities associated with the intent
pub entities: Vec<EntityBasic>,
}
impl WitClient {
/// Get basic information about all intents associated with an app
///
/// Example:
/// ```rust,no_run
/// # tokio_test::block_on(async {
/// # use wit_ai_rs::client::WitClient;
/// # use wit_ai_rs::IntentBasic;
/// # let wit_client = WitClient::new(String::new(), String::new());
/// let response: Vec<IntentBasic> = wit_client.get_intents().await.unwrap();
/// # })
/// ```
pub async fn get_intents(&self) -> Result<Vec<IntentBasic>, Error> {
self.make_request(Method::GET, "/intents", vec![], Option::<Value>::None)
.await
}
/// Create a new intent
///
/// Example:
/// ```rust,no_run
/// # tokio_test::block_on(async {
/// # use wit_ai_rs::client::WitClient;
/// # use wit_ai_rs::IntentBasic;
/// # let wit_client = WitClient::new(String::new(), String::new());
/// let response: IntentBasic = wit_client.create_intent("intent_name").await.unwrap();
/// # })
/// ```
pub async fn create_intent(&self, intent_name: &str) -> Result<IntentBasic, Error> {
let new_intent = json!({"name": intent_name});
self.make_request(Method::POST, "/intents", vec![], Some(new_intent))
.await
}
/// Get more detailed information about a specific intent
///
/// Example:
/// ```rust,no_run
/// # tokio_test::block_on(async {
/// # use wit_ai_rs::client::WitClient;
/// # use wit_ai_rs::intents::IntentResponse;
/// # let wit_client = WitClient::new(String::new(), String::new());
/// let response: IntentResponse = wit_client.get_intent("intent_name").await.unwrap();
/// # })
/// ```
pub async fn get_intent(&self, intent_name: &str) -> Result<IntentResponse, Error> {
let endpoint = format!("/intents/{}", intent_name);
self.make_request(Method::GET, &endpoint, vec![], Option::<Value>::None)
.await
}
/// Delete an intent by name
///
/// Example:
/// ```rust,no_run
/// # tokio_test::block_on(async {
/// # use wit_ai_rs::client::WitClient;
/// # use wit_ai_rs::DeleteResponse;
/// # let wit_client = WitClient::new(String::new(), String::new());
/// let response: DeleteResponse = wit_client.delete_intent("intent_name").await.unwrap();
/// # })
/// ```
pub async fn delete_intent(&self, intent_name: &str) -> Result<DeleteResponse, Error> {
let endpoint = format!("/intents/{}", intent_name);
self.make_request(Method::DELETE, &endpoint, vec![], Option::<Value>::None)
.await
}
}