pub struct Dialogflow { /* private fields */ }
Expand description
An authenticated Dialogflow client
Implementations§
Source§impl Dialogflow
impl Dialogflow
Sourcepub async fn new() -> Result<Self, DialogflowError>
pub async fn new() -> Result<Self, DialogflowError>
Initializes Dialogflow
Multiple strategies are used to authenticate the client, please refer to
gcp_auth
for more information.
pub fn with_detect_intent_options( self, detect_intent_options: DetectIntentOptions, ) -> Self
Sourcepub async fn detect_intent_serde<I: DeserializeOwned>(
&self,
text: &str,
) -> Result<I, DialogflowError>
pub async fn detect_intent_serde<I: DeserializeOwned>( &self, text: &str, ) -> Result<I, DialogflowError>
Detects an intent and returns the result as serde
-deserialized enum, I
The enum must be shaped as follows:
- The name of each enum variant should be the same as a Dialogflow intent name
- The variants may only be, either:
- A unit variant, for intents with no parameters
- A struct variant, whose fields correspond to paramter names
§Enum definition example
#[derive(serde::Deserialize)]
#[serde(rename_all = "snake_case")]
enum Intent {
Hello,
Weather {
location: String,
},
ThankYou,
}
In this case, the intents are named hello
, weather
and thank_you
.
§Call example
#[derive(Debug, Eq, PartialEq, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
enum Intent {
Hello,
Goodbye,
}
let intent = dialogflow.detect_intent_serde::<Intent>("Hello !").await.unwrap();
assert_eq!(intent, Intent::Hello);
§Unknown intent
If the Dialogflow API cannot recognize an intent, this function will attempt to deserialize
a variant called unknown
on your enum. This allows you to know that the text wasn’t
recognized without having to deal with an Err
.
Auto Trait Implementations§
impl !Freeze for Dialogflow
impl !RefUnwindSafe for Dialogflow
impl Send for Dialogflow
impl Sync for Dialogflow
impl Unpin for Dialogflow
impl !UnwindSafe for Dialogflow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more