Swift package as module for interfacing with SAP Conversational AI in native iOS apps.

What's New


New feature(s) are non-breaking and do not change behavior unless app developer adopts actively


  • 🎸 client-side handling of delayed messages (2d3bed2)
  • 🎸 delayed message(s) are visually announced (5015477)

Bug Fixes

  • 🐛 "Trigger Skill" button inside card posts data correctly (da9a309)
  • 🐛 action button layout for different size class (#27) (399f3b2)
  • 🐛 avoid "A server error occurred" msgs related to polling (942096a)
  • 🐛 avoid "Request was cancelled" error message (9cc3907)
  • 🐛 avoid endless polling for continuous server errors (e94482d)
  • 🐛 fix "Failed to parse" for custom Text messages (30bcf40)
  • 🐛 handle phonenumber button type with "tel:" prefix (#24) (791f960)
  • 🐛 Hide "view more" button for <= 5 buttons in list (f9a2cf6)
  • 🐛 icon color appropiate to color scheme (dark/light) (2744ffc)
  • 🐛 Localize UI text "View more" (31480bf)
  • 🐛 Localize UI texts "Clear", "Actions" and "Cancel" (450df11)
  • 🐛 only show link email and phone number as clickable (#31) (395552d)
  • 🐛 show 'View More' button in list (4540ca9)
  • 🐛 showing the first 11 Quick replies only (9a1027b)
  • 🐛 start polling (if paused) after user sent message to bot (6f89298)
  • 🐛 start polling after conversation was created (29a4ddc)
  • 🐛 UI improvement for error banner (955be18)

SAP Conversational AI SDK for iOS

The SAPCAI Swift Package is a module to connect to a bot on the end-to-end chatbot platform SAP Conversational AI (CAI). It provides a pluggable SwiftUI AssistantView to initiate a conversation and render the various message types of a bot.

This Swift Package is an open-source addition to the SAP BTP SDK for iOS.

SwiftUI AssistantView


  • iOS 13 or higher
  • Xcode 12 (Swift 5.3) or higher


  • You have existing bot(s) on the SAP Conversational AI platform
  • You created an OAuth client for Designtime API for your bot (Settings > Tokens)
  • Your bot(s) are connected to a mobile channel

Create a mobile channel

In the Enterprise Edition you create a mobile channel via the UI.



However, the option is currently hidden by default and must be enabled by filing a ticket.

In the Community Edition you create a mobile channel via the /channel API.

# create a mobile channel
curl -X POST "<BaseUrl>/connect/v1/channels" \
-H "X-Token: Token <DeveloperToken>" \
-H "Content-Type: application/json" \
-d '{"type":"mobile","slug":"<desiredChannelSlug>","connectionTarget": "SAP_Product","targetSystem": "MobileBot","isActivated":true}'


  • SAPCommon for Logging
  • SAPFoundation for Network Connectivity and Authentication
  • URLImage for asynchronous image loading in SwiftUI
  • Down for Markdown / CommonMark rendering in Swift


The package is intended for consumption via Swift Package Manager. To add SAPCAI to your application target, navigate to the File > Swift Packages > Add Package Dependency... , then add the repository URL

You can choose one of the following package products to be added to your application/framework target.

Package Product When to Use
SAPCAI You did not already embed binary frameworks from SAP BTP SDK for iOS
SAPCAI-requiresToEmbedXCFrameworks You already embedded SAPCommon and SAPFoundation binary frameworks to your target

Getting Started

The code snippet below illustrates setting up the CAIConversation Combine publisher to initialize the MessagingViewModel for the AssistantView. For prototyping you can connect the iOS client directly with SAP Conversational AI Community Edition. You have to replace variable values in angle brackets (e.g. <channelId>) with your bot-specific values.

See Enterprise Configuration guide for required configuration steps to use SAPCAI Swift package and connect indirectly with SAP Conversational AI Enterprise Edition through SAP Mobile Services.

Setting up the data publisher

import SAPCAI
import SAPFoundation
import SwiftUI

  Create the `CAIChannel` object by providing the channel id, channel token, and channel slug, which were created in CAI Platform.

  If you do not want to hardcode channel information on the client, you can retrieve a list of channels for a given Application ID with `CAIChannelService`.
let caiChannel = CAIChannel(id: "<channelId>", token: "<channelToken>", slug: "<channelSlug>").

// Create CAI service config for a SAPURLSession and URL pointing to CAI API endpoint
let serviceConfig = CAIServiceConfig(urlSession: SAPURLSession(), host: URL(string:"<Example:>")!)
// Provide the message delivery object for polling
let polling: MessageDelivering = PollMessageDelivery(channelId: "<channelId>", serviceConfig: serviceConfig)
// Create CAIConversation object and use it as publisher
let dataPublisher = CAIConversation(config: serviceConfig, channel: caiChannel, messageDelivery: polling)

// Create view model for `AssistantView`
let viewModel = MessagingViewModel(publisher: dataPublisher)

User Interface

Using the SwiftUI implementation is the preferred approach.

  .navigationBarTitle(Text("Chat"), displayMode: .inline) // if you are in navigation controller
  .onDisappear {

but SAPCAI also provides a UIKit wrapper

let vc = MessagingViewController(MessagingViewModel(publisher: dataPublisher))

self.navigationController?.pushViewController(vc, animated: true)


SAPCAI will provide two standard themes

  • a Fiori theme and
  • a Casual theme


Each theme will come with a color palette that supports both light and dark modes.

Fiori theme

ThemeManager.shared.setCurrentTheme( .fiori(FioriColorPalette()) )

Casual theme

ThemeManager.shared.setCurrentTheme( .casual(CasualColorPalette()) )

Create your own custom theme

You can also provide an alternative color palette or provide a custom theme.


Markdown related

Trigger Skill button related

  • Trigger Skill buttons are still enabled after execution / next interaction. This behavior differs from SAP CAI WebClient. Once you click the button or type an utterance, the corresponding skill can't be triggered anymore at a later point in time since the context in which it was created might not be valid anymore.

Image related

  • Not being able to save, copy, or share an image as part of a bot response. Currently, there is no gesture handler attached to an image view which could allow opening a contextual menu offering such features (similar to iMessage or WhatsApp).
  • Animated images (GIF), as part of a bot response, will be viewed as a static image (dependency to

How to obtain support

Please raise an issue on GitHub. SAP customers can continue to report issues through OSS for SLA tracking.

Raise questions around CAI in the SAP CAI Answers forum.


If you want to contribute, please check the Contribution Guidelines.


The CAITestApp in this repository allows you to

  • choose a theme
  • view static mock data or
  • connect against a live system by either
    • letting the user choose the mobile channel from the list of available mobile channels for given Application ID (a.k.a targetSystem); note: this illustrates the use of CAIChannelService and how to build a simple SwiftUI view on top of it
    • loading the AssistantView for a specific mobile channel

See here on how to maintain connection settings for the test application.


  • Swift Tools 5.3.0
View More Packages from this Author


Last updated: Mon Oct 18 2021 00:48:34 GMT-0500 (GMT-05:00)