# References

## Use the library

Include this javascript bundle in the html

```html
<script src="https://static.iadvize.com/conversation-panel-app-lib/2.9.0/idzcpa.umd.production.min.js"></script>
```

## Client

### idzCpa

Global cariable used as the entry point of the CPA library, stored in window

#### init() : Promise

Client is obtained using idzCpa.init that returns a Promise

```typescript
window.idzCpa.init().then(client => {
    //some code
})
```

#### context

Returns the client's information in the form of a Context object

```typescript
 type Context = {
    conversationId: string;
    projectId: string;
    channel: Channel;
    language: string;
}
```

conversationId : id of the conversation between the client and the operator

projectId : Id of the project you launch the desk on

channel : Type of channel :

```
  AppleBusinessChat = 'APPLE_BUSINESS_CHAT',
  Call = 'CALL',
  Chat = 'CHAT',
  Facebook = 'FACEBOOK',
  FacebookBusinessOnMessenger = 'FACEBOOK_BUSINESS_ON_MESSENGER',
  MobileApp = 'MOBILE_APP',
  Sms = 'SMS',
  Video = 'VIDEO',
  Whatsapp = 'WHATSAPP',
```

language : language of the client

### insertTextInComposeBox(string)

Insert the text passed in parameters into the compose box

### pushCardInConversationThreat(Card)

Push the card passed in parameters into the conversation thread

```typescript
type Action = {
  type: "LINK";
  title: string;
  url: string;
};

type Card = {
  title?: string;
  text?: string;
  actions: Action[];
  image?: {
      url: string;
      description: string;
  }
};

```

### pushCardBundleInConversationThread(Carousel)

Push the card bundle passed in parameters in the conversation thread

```typescript
type Carousel = {
  title?:string;
  cards: Card[]
}
```

### getJWT() : string

Returns the JWT of the desk

## ApplePay

### pushApplePayPaymentRequestInConversationThread(ApplePayPaymentRequestType) : Promise

Insert an ApplePay payment request in the conversation, returns a promise.\
If the payment is successful => execute `promise.then(()=>{ })`\
If there is an error in the payment => execute `promise.catch((e : ActionError)=>{ })`

```typescript
type ApplePayPaymentRequestType = {
    requestIdentifier: UUID;
    payment: ApplePayPaymentRequest;
    receivedMessage: ApplePayReceivedMessage;
}

// Detail for payment field type
type ApplePayPaymentRequest {
  currencyCode: string;
  lineItems: PaymentItem[];
  requiredBillingContactFields: ApplePayContactField[];
  requiredShippingContactFields: ApplePayContactField[];
  shippingMethods: ShippingMethod[];
  total: PaymentItem;
}

type PaymentItem = {
  amount: string;
  label: string;
  type: ApplePayLineItemType;
};

enum ApplePayLineItemType {
  final,
  pending,
}

type ShippingMethod = {
  amount: string;
  detail: string;
  identifier: string;
  label: string;
};

enum ApplePayContactField {
  email = 'email',
  name = 'name',
  phone = 'phone',
  postalAddress = 'postalAddress',
  phoneticName = 'phoneticName',
}

// type for receivedMessage field
type ApplePayReceivedMessage {
  type: 'CARD';
  data: CardType;
}

type CardType = {
  title?: string;
  text?: string;
  image?: CardImage;
  actions: LinkAction[];
};

type CardImage = {
  url: string;
  description: string;
};

type LinkAction = {
  type: 'LINK';
  title: string;
  url: string;
};

// Error
type ActionError = {
    message: string;
    details?: string[];
}

client.pushApplePayPaymentRequestInConversationThread(applePayPaymentRequest: ApplePayPaymentRequestType): Promise
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iadvize.dev/use-cases/agent-workspace/custom-app-example-and-step-by-step-tutorial/references.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
