# Campaigns

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

Add campaigns to video, chat, scheduled, or virtual agent views. First request the campaign, then use the target campaign as an entry, and finally start the callback.

## Request the campaign

Use the API defined in the `ZoomCCInterface` class to retrieve campaigns using `CampaignApiKey`.

Get the `CampaignApiKey` value from your Contact Center admin, who can find this at **Campaign Management** > **Web and In-App** > **`</>Embed Web Tag`**.

```kotlin
val service = ZoomCCInterface.getZoomCCWebCampaign()
service.init(
    ZoomCCItem(
        apiKey = CampaignApiKey,
        sdkType = ZoomCCIInterfaceType.CAMPAIGN,
        serverType = CCServerType.CCServerWWW
    )
)
val ret = service.requestCampaign {
    campaignInfoList = it
    updateUI(it)
}
```

```java
ZoomCCWebCampaignService service = ZoomCCInterface.INSTANCE.getZoomCCWebCampaignService();
service.init(new ZoomCCItem(null, apiKey, ZoomCCIInterfaceType.CAMPAIGN, serverType));

int ret = service.requestCampaign(result -> {
    campaignInfoList = result;
    return null;
});
```

## Use the target campaign as an entry

After fetching all the campaigns, choose one `ZoomCCCampaignInfocampaignInfo` and use it as an entry to the chat, video, scheduled callback, or virtual agent channel.

The campaignInfo's `translatedCampaignChannels` property is an array that contains all channel types: `ZoomCCIInterfaceType_Chat`, `ZoomCCIInterfaceType_Video`, `ZoomCCIInterfaceType_ZVA`, and `ZoomCCIInterfaceType_ScheduledCallback`.

```kotlin
private fun initWithInterfaceType(type: ZoomCCIInterfaceType, info: ZoomCCCampaignInfo) {
    when (type) {
        ZoomCCIInterfaceType.CHAT -> createChatEntry(info)
        ZoomCCIInterfaceType.ZVA -> createZVAEntry(info)
        ZoomCCIInterfaceType.VIDEO -> createVideoEntry(info)
        ZoomCCIInterfaceType.SCHEDULED_CALLBACK -> createScheduledCallbackEntry(info)
        else -> {}
    }
}
```

```java
private void initWithInterfaceType(ZoomCCIInterfaceType type, ZoomCCCampaignInfo info) {
    switch (type) {
        case CHAT:
            createChatEntry(info);
            break;
        case ZVA:
            createZVAEntry(info);
            break;
        case VIDEO:
            createVideoEntry(info);
            break;
        case SCHEDULED_CALLBACK:
            createScheduledCallbackEntry(info);
            break;
    }
}
```

## Start the chat, video, scheduled, or virtual agent callbacks

-   [chat](#show-the-chat-view-in-the-campaign-mode)
-   [virtual agent chat](#show-the-virtual-agent-chat-view-in-the-campaign-mode)
-   [video](#show-the-video-view-in-the-campaign-mode)
-   [scheduled](#show-the-scheduled-callback-view-in-the-campaign-mode)

### Show the chat view in the campaign mode

1. Create a `ZoomCCItem` class instance.
1. Set the item's `sdkType` to `ZoomCCIINterfaceType_Chat`.
1. Set the item's `apiKey` to `APP_CAMPAIGN_API_KEY`.
1. Set the item's `useCampaignMode` property to `YES`.
1. Set the item's `campaignInfo` property to `campaignInfo`.
1. Get `chatService` and end the previous `chatService` if needed.
1. Initialize `chatService` with the item previously created and log in with `chatService` if its status is `ZoomCCSDKStatus_Initial`.
1. Fetch and show the chat view using `chatService`'s `fetchUI` API.

```kotlin
private fun createChatEntry(info: ZoomCCCampaignInfo) {
    var service = ZoomCCInterface.getZoomCCChatService()
    service.getZoomCCItem()?.campaignInfo?.let {        if (info.campaignId != it.campaignId) {
            service.endChat()
            service = ZoomCCInterface.getZoomCCChatService()
        }
    }    service.init(
        ZoomCCItem(
            apiKey = apiKey,
            sdkType = ZoomCCIInterfaceType.CHAT,
            serverType = serverType,
            useCampaignMode = true,
            campaignInfo = info
        )
    )
    service.login()
    service.fetchUI()
}
```

```java
private void createChatEntry(ZoomCCCampaignInfo info) {
    ZoomCCChatService service = ZoomCCInterface.INSTANCE.getZoomCCChatService();
    ZoomCCItem item = service.getZoomCCItem();
    if (item != null && item.getCampaignInfo() != null) {
        if (Objects.equals(info.getCampaignId(), item.getCampaignInfo().getCampaignId())) {
            service.endChat();
            service = ZoomCCInterface.INSTANCE.getZoomCCChatService();
        }
    }
    service.init(new ZoomCCItem(null, apiKey, ZoomCCIInterfaceType.CHAT, serverType, true, info));
    service.login();
    service.fetchUI();
}
```

### Show the virtual agent chat view in the campaign mode

1. Create a `ZoomCCItem` class instance.
1. Set the item's `sdkType` to `ZoomCCIINterfaceType_ZVA`.
1. Set the item's `apiKey` to `APP_CAMPAIGN_API_KEY`.
1. Set the item's `useCampaignMode` property to `YES`.
1. Set the item's `campaignInfo` property to `campaignInfo`.
1. Get `zvaService` and end the previous `zvaService` if needed.
1. Initialize `zvaService` with the item previously created, and log in with `zvaService` if its status is `ZoomCCSDKStatus_Initial`.
1. Fetch and show the virtual agent view using `zvaService`'s `fetchUI` API.

```kotlin
private fun createZVAEntry(info: ZoomCCCampaignInfo) {
    var service = ZoomCCInterface.getZoomCCZVAService()
    service.getZoomCCItem()?.campaignInfo?.let {        if (info.campaignId != it.campaignId) {
            service.endChat()
            service = ZoomCCInterface.getZoomCCZVAService()
        }
    }    service.init(
        ZoomCCItem(
            apiKey = apiKey,
            sdkType = ZoomCCIInterfaceType.ZVA,
            serverType = serverType,
            useCampaignMode = true,
            campaignInfo = info
        )
    )
    service.fetchUI()
}
```

```java
private void createZVAEntry(ZoomCCCampaignInfo info) {
    ZoomCCChatService service = ZoomCCInterface.INSTANCE.getZoomCCZVAService();
    ZoomCCItem item = service.getZoomCCItem();
    if (item != null && item.getCampaignInfo() != null) {
        if (Objects.equals(info.getCampaignId(), item.getCampaignInfo().getCampaignId())) {
            service.endChat();
            service = ZoomCCInterface.INSTANCE.getZoomCCZVAService();
        }
    }
    service.init(new ZoomCCItem(null, apiKey, ZoomCCIInterfaceType.ZVA, serverType, true, info));
    service.fetchUI();
}
```

### Show the video view in the campaign mode

1. Create a `ZoomCCItem` class instance.
1. Set the item's `sdkType` to `ZoomCCIINterfaceType_Video`.
1. Set the item's `apiKey` to `APP_CAMPAIGN_API_KEY`.
1. Set the item's `useCampaignMode` property to `YES`.
1. Set the item's `campaignInfo` property to `campaignInfo`.
1. Get `videoService` and end the previous `videoService` if needed.
1. Set `videoPreviewOptions` and `autoJoinWhenVideoCreated` property of `videoService`.
1. Initialize `videoService` with the item previously created if its status is `ZoomCCSDKStatus_Initial`.
1. Fetch and show the video view using `videoService`'s `fetchUI` API.

```kotlin
private fun createVideoEntry(info: ZoomCCCampaignInfo) {
    var service = ZoomCCInterface.getZoomCCVideoService()
    service.getZoomCCItem()?.campaignInfo?.let {        if (info.campaignId != it.campaignId) {
            // no need to executive service.endVideo()
            ZoomCCInterface.releaseZoomCCService(service.getKey())
            service = ZoomCCInterface.getZoomCCVideoService()
        }
    }    service.init(
        ZoomCCItem(
            apiKey = apiKey,
            sdkType = ZoomCCIInterfaceType.VIDEO,
            serverType = serverType,
            useCampaignMode = true,
            campaignInfo = info
        )
    )
    service.setVideoPreviewOption(VideoPreviewOption.ZmCCVideoPreviewOptionDefault)
    service.setAutoJoinWhenVideoCreated(false)
    service.setUseBackwardFacingCameraByDefault(false)
    service.addListener(object : ZoomCCVideoListener {})
    service.fetchUI()
}
```

```java
private void createVideoEntry(ZoomCCCampaignInfo info) {
    ZoomCCVideoService service = ZoomCCInterface.INSTANCE.getZoomCCVideoService();
    ZoomCCItem item = service.getZoomCCItem();
    if (item != null && item.getCampaignInfo() != null) {
        if (Objects.equals(info.getCampaignId(), item.getCampaignInfo().getCampaignId())) {
            // no need to executive service.endVideo()
            ZoomCCInterface.INSTANCE.releaseZoomCCService(service.getKey());
            service = ZoomCCInterface.INSTANCE.getZoomCCVideoService();
        }
    }
    service.init(new ZoomCCItem(null, apiKey, ZoomCCIInterfaceType.VIDEO, serverType, true, info));
    service.setVideoPreviewOption(VideoPreviewOption.ZmCCVideoPreviewOptionDefault);
    service.setAutoJoinWhenVideoCreated(false);
    service.setUseBackwardFacingCameraByDefault(false);
    service.addListener(new ZoomCCVideoListener() {
        @Override        public void onClientEvent(@NonNull ClientEvent clientEvent) {}
        @Override        public void onEngagementEnd(@NonNull String s) {}
        @Override        public void onEngagementStart(@NonNull String s) {}
        @Override        public void onError(int i, long l, @NonNull String s) {}
        @Override        public void onLoginStatus(@Nullable IMStatus imStatus) {}
        @Override        public void unreadMsgCountChanged(int i) {}
    });
    service.fetchUI();
}
```

### Show the scheduled callback view in the campaign mode

1. Create a `ZoomCCItem` class instance.
1. Set the item's `sdkType` to `ZoomCCIINterfaceType_ScheduledCallback`.
1. Set the item's `apiKey` to `APP_CAMPAIGN_API_KEY`.
1. Set the item's `useCampaignMode` property to `YES`.
1. Set the item's `campaignInfo` property to `campaignInfo`.
1. Initialize `scheduledCallbackService` with the item previously created, and log in with `chatService`.
1. Fetch and show the scheduled callback view using `scheduledCallbackService`'s `fetchUI` API.

```kotlin
private fun createScheduledCallbackEntry(info: ZoomCCCampaignInfo) {
    val service = ZoomCCInterface.getZoomCCScheduledCallbackService()
    service.init(
        ZoomCCItem(
            apiKey = apiKey,
            sdkType = ZoomCCIInterfaceType.SCHEDULED_CALLBACK,
            serverType = serverType,
            useCampaignMode = true,
            campaignInfo = info
        )
    )
    service.fetchUI()
}
```

```java
private void createScheduledCallbackEntry(ZoomCCCampaignInfo info) {
    ZoomCCScheduledCallbackService service = ZoomCCInterface.INSTANCE.getZoomCCScheduledCallbackService();
    service.init(new ZoomCCItem(null, apiKey, ZoomCCIInterfaceType.SCHEDULED_CALLBACK, serverType, true, info));
    service.fetchUI();
}
```
