Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Client for the OpenIntents agentic API.

use openintents::{Client, CreateIntent};

let oi = Client::from_env()?; // OPENINTENTS_API_KEY
let intent = oi.create_intent(CreateIntent::new("flat white, oat milk").max_amount(1000)).await?;
let intent = oi.wait(&intent.id, Default::default()).await?;
if let Some(payment) = &intent.payment {
    println!("pay here: {}", payment.payment_url);
}

Implementations§

Source§

impl Client

Source

pub fn new(api_key: impl Into<String>) -> Self

A client with the given API key and default settings.

Source

pub fn from_env() -> Result<Self>

Reads OPENINTENTS_API_KEY (and OPENINTENTS_BASE_URL, if set).

Source

pub fn builder(api_key: impl Into<String>) -> ClientBuilder

Source

pub async fn create_intent(&self, params: CreateIntent) -> Result<Intent>

Start an intent. Returns immediately, usually with status queued. Sends a fresh Idempotency-Key; use Client::create_intent_idempotent to set your own.

Source

pub async fn create_intent_idempotent( &self, params: CreateIntent, idempotency_key: &str, ) -> Result<Intent>

Source

pub async fn get_intent(&self, id: &str) -> Result<Intent>

Source

pub async fn create_intent_waiting( &self, params: CreateIntent, wait_secs: u32, ) -> Result<Intent>

Client::create_intent, holding the request up to wait_secs whole seconds (Prefer: wait=N, applied as 50 at most) until the intent is neither queued nor running: it finished, or now needs a payment, an answer or a sign-in. A hold that runs out is no error: the intent comes back as it stands. The client’s timeout is stretched to outlast the hold.

Source

pub async fn get_intent_waiting( &self, id: &str, wait_secs: u32, ) -> Result<Intent>

Source

pub async fn list_intents(&self, params: &ListIntents) -> Result<IntentList>

Source

pub async fn cancel_intent(&self, id: &str) -> Result<Intent>

Cancel an intent that hasn’t paid yet. Cancelled intents are free.

Source

pub async fn answer_intent_input( &self, id: &str, answer: AnswerInput, ) -> Result<Intent>

Answer the intent’s input_request while it waits in requires_input. Returns the intent, usually running again. A request already answered or expired is a 409 input_not_waiting. Sends a fresh Idempotency-Key, so a retry never answers twice.

use openintents::AnswerInput;

if let Some(request) = &intent.input_request {
    // Ask the payer `request.prompt`, then:
    oi.answer_intent_input(&intent.id, AnswerInput::value(&request.id, "481516"))
        .await?;
}
Source

pub async fn balance(&self) -> Result<Balance>

The agent balance intents pay from, and this month’s spend.

Source

pub async fn balance_for(&self, customer: &str) -> Result<Balance>

A customer’s balance.

Source

pub async fn create_customer(&self, params: CustomerParams) -> Result<Customer>

Someone you buy for, with their own balance and browser profile. Sends a fresh Idempotency-Key; use Client::create_customer_idempotent to set your own.

Source

pub async fn create_customer_idempotent( &self, params: CustomerParams, idempotency_key: &str, ) -> Result<Customer>

Source

pub async fn get_customer(&self, id: &str) -> Result<Customer>

Source

pub async fn update_customer( &self, id: &str, params: CustomerParams, ) -> Result<Customer>

Fields left out stay as they are (see CustomerParams).

Source

pub async fn list_customers( &self, params: &ListCustomers, ) -> Result<CustomerList>

Newest first.

Source

pub async fn create_topup(&self, params: CreateTopup) -> Result<Topup>

A payment link that adds amount to a balance once paid. Live keys only. Sends a fresh Idempotency-Key; use Client::create_topup_idempotent to set your own.

Source

pub async fn create_topup_idempotent( &self, params: CreateTopup, idempotency_key: &str, ) -> Result<Topup>

Source

pub async fn get_topup(&self, id: &str) -> Result<Topup>

Source

pub async fn list_intent_events( &self, id: &str, params: &ListEvents, ) -> Result<EventList>

A page of the intent’s timeline, oldest first: status changes, the agent’s steps, its checkout.

Source

pub fn stream_intent_events( &self, id: &str, last_event_id: Option<&str>, ) -> EventStream

Follow the intent’s timeline live: past events first, then new ones as they happen, after last_event_id if given. The stream resumes by itself after a dropped connection, and ends once the intent is over and its last event was sent.

let mut events = oi.stream_intent_events("int_7f3a2c", None);
while let Some(event) = events.next().await {
    let event = event?;
    println!("{} {}", event.kind, event.data);
}
Source

pub async fn list_profiles(&self, params: &ListProfiles) -> Result<ProfileList>

Your account’s profile and your customers’ that exist so far, newest first.

Source

pub async fn create_profile(&self, params: CreateProfile) -> Result<Profile>

Make the profile of your account, or of a customer, ahead of its first intent or session. Optional: an intent makes the profile it needs. Making one that exists returns it unchanged, so no Idempotency-Key is sent.

Source

pub async fn get_profile(&self, id: &str) -> Result<Profile>

Source

pub async fn forget_profile(&self, id: &str) -> Result<Profile>

Erase everything the profile kept: logins, cookies, saved data. Returns it forgetting, then it turns forgotten. Forgetting twice is fine.

Source

pub async fn create_session(&self, params: CreateSession) -> Result<Session>

Open a browser on a profile without an intent. A profile in use is a 409 profile_busy whose lease says what holds it. Sends a fresh Idempotency-Key; use Client::create_session_idempotent to set your own.

Source

pub async fn create_session_idempotent( &self, params: CreateSession, idempotency_key: &str, ) -> Result<Session>

Source

pub async fn get_session(&self, id: &str) -> Result<Session>

Source

pub async fn list_sessions(&self, params: &ListSessions) -> Result<SessionList>

Newest first.

Source

pub async fn release_session(&self, id: &str) -> Result<Session>

Close the browser, keeping what the session changed in the profile. A session that already ended is returned unchanged.

Source

pub async fn run_session_command( &self, id: &str, command: SessionCommand, ) -> Result<SessionCommandResult>

Run one command on the session’s page. It waits up to 20 seconds; a command still running then comes back Pending, to follow with Client::get_session_command. A refused or failed one says why in error. Sends a fresh Idempotency-Key, so a retry never runs it twice; use Client::run_session_command_idempotent to set your own.

Source

pub async fn run_session_command_idempotent( &self, id: &str, command: SessionCommand, idempotency_key: &str, ) -> Result<SessionCommandResult>

Source

pub async fn get_session_command( &self, id: &str, command_id: &str, ) -> Result<SessionCommandResult>

Source

pub async fn session_screenshot(&self, id: &str) -> Result<Vec<u8>>

A screenshot of the session’s page, taken now: JPEG bytes.

Source

pub async fn list_session_events( &self, id: &str, params: &ListEvents, ) -> Result<EventList>

A page of the session’s timeline, oldest first: status changes, pages and commands.

Source

pub fn stream_session_events( &self, id: &str, last_event_id: Option<&str>, ) -> EventStream

Follow the session’s timeline live, like Client::stream_intent_events.

A link to the session’s live view, valid for 10 minutes. Whoever holds url sees the browser and drives it, though never to pay or place an order. The session must be open. Each call makes a new link.

Source

pub async fn create_portal_session( &self, customer: &str, params: CreatePortalSession, ) -> Result<PortalSession>

A link to a customer’s own page, shown once: send url to the customer only. Until portal sessions are open to your key this is a 503 portal_unavailable.

Source

pub async fn create_secret_request( &self, customer: &str, params: CreateSecretRequest, ) -> Result<SecretRequestCreated>

Ask a customer for their secrets on a page of their own. Send them the url; its end is a secret_request.completed webhook.

Source

pub async fn get_secret_request(&self, id: &str) -> Result<SecretRequest>

Where a request for a customer’s secrets stands.

Source

pub async fn create_secret(&self, params: CreateSecret) -> Result<Secret>

Store details a purchase may need and that you would not put in a prompt. Secrets are write-only: one comes back as its label, a mask and a few public fields, never its values. Sends a fresh Idempotency-Key.

Source

pub async fn list_secrets(&self, params: &ListSecrets) -> Result<SecretList>

A payer’s secrets in the key’s mode, without their values: your account’s, or a customer’s.

Source

pub async fn get_secret(&self, id: &str) -> Result<Secret>

Source

pub async fn replace_secret( &self, id: &str, params: CreateSecret, ) -> Result<Secret>

Replace a secret’s whole content; its version goes up.

Source

pub async fn delete_secret(&self, id: &str) -> Result<()>

Delete a secret and its values.

Source

pub async fn list_secret_uses( &self, id: &str, page: &Page, ) -> Result<SecretUseList>

A secret’s history, newest first: made, replaced, filled into a shop or refused. Never a value.

Source

pub async fn create_sign_in(&self, params: CreateSignIn) -> Result<SignIn>

A link where the payer signs in to a shop with no intent attached; the profile keeps the login. Send them url. Its end is a sign_in.completed or sign_in.expired webhook.

Source

pub async fn get_sign_in(&self, id: &str) -> Result<SignIn>

Source

pub async fn create_webhook_endpoint( &self, params: CreateWebhookEndpoint, ) -> Result<WebhookEndpoint>

Register a URL for your account’s events. The response alone carries its secret: keep it.

Source

pub async fn list_webhook_endpoints( &self, page: &Page, ) -> Result<WebhookEndpointList>

Newest first, without their secrets.

Source

pub async fn get_webhook_endpoint(&self, id: &str) -> Result<WebhookEndpoint>

Source

pub async fn update_webhook_endpoint( &self, id: &str, params: UpdateWebhookEndpoint, ) -> Result<WebhookEndpoint>

Change its URL, its event types (an empty list is every intent event) or whether it is disabled.

Source

pub async fn delete_webhook_endpoint(&self, id: &str) -> Result<()>

Source

pub async fn rotate_webhook_secret(&self, id: &str) -> Result<WebhookEndpoint>

Make a new secret, returned here only. The one before keeps signing for 24 hours; verify_webhook accepts a header that carries both.

Source

pub async fn test_webhook_endpoint(&self, id: &str) -> Result<WebhookDelivery>

Send a webhook_endpoint.test event to this endpoint alone; the delivery shows how it goes.

Source

pub async fn list_webhook_deliveries( &self, id: &str, page: &Page, ) -> Result<WebhookDeliveryList>

What was sent to the endpoint, newest first.

Source

pub async fn redeliver_webhook( &self, endpoint: &str, delivery: &str, ) -> Result<WebhookDelivery>

Send a delivery again, with the same event id and body.

Source

pub async fn wait(&self, id: &str, opts: WaitOptions) -> Result<Intent>

Poll until the intent is final, or (by default) waits on a person: its payment, an answer from its payer, or its payer’s sign-in.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more