iOS & Swift Package
Add the Asyntai AI chatbot to your iPhone, iPad or Mac app
Overview
The Asyntai Swift package puts your AI chatbot inside your own app. Add the package with Swift Package Manager, give it your widget ID, and show the chat as a SwiftUI view or a UIKit view controller.
It is the same assistant as on your website, with the same knowledge, colours and settings. It answers your app users from your own content, in more than 80 languages, day and night.
Requirements
- iOS 14 or later, or macOS 11 or later
- Xcode 15 or later (Swift 5.9 or later)
- An Asyntai account. The Free plan is enough to try the chat
Installation
Follow these steps to add Asyntai to your app:
Get Your Widget ID
Sign in to Asyntai and open the Install page. The widget ID is the value of data-asyntai-id in the snippet shown there. It starts with asyntai_.
Add the Package
In Xcode, choose File > Add Package Dependencies and enter this URL:
https://github.com/asyntai/swift-ai-chatbot.git
Add the AsyntaiAIChatbot library to your app target. In a Package.swift file, use:
.package(url: "https://github.com/asyntai/swift-ai-chatbot.git", from: "1.0.0")
Show the Chat in SwiftUI
Open the chat as a sheet from any button:
import SwiftUI
import AsyntaiAIChatbot
struct HelpButton: View {
@State private var showChat = false
private let chat = try! AsyntaiConfiguration(widgetId: "asyntai_1a2b3c4d5e6f")
var body: some View {
Button("Chat with us") { showChat = true }
.sheet(isPresented: $showChat) {
AsyntaiChatView(configuration: chat) { event in
if event == .closed { showChat = false }
}
}
}
}
Or Show the Chat in UIKit
Present the view controller. It closes itself when the user closes the chat:
import AsyntaiAIChatbot
let config = try AsyntaiConfiguration(widgetId: "asyntai_1a2b3c4d5e6f")
present(AsyntaiChatViewController(configuration: config), animated: true)
Options
All options go in AsyntaiConfiguration.
| Option | Type | Default | What it does |
|---|---|---|---|
widgetId | String | required | Your Asyntai widget ID |
pageURL | URL | https://asyntai.com/ | The page address the chat reports. Set it to your website to see it on app chats in the dashboard |
opensAutomatically | Bool | true | Opens the chat window at once. Set it to false to show the chat button first |
scriptURL | URL | the Asyntai CDN | Advanced. Load the widget from another URL |
A missing or malformed widgetId throws an AsyntaiConfigurationError with a message that says how to fix it.
Chat Events
The onEvent closure receives .ready when the chat has loaded, .opened when the chat window opens, and .closed when the user closes it. Use .closed to dismiss your sheet or screen.
Links in chat answers open in the system browser, so the conversation stays in your app.
Answering From Your Content
Asyntai reads your published pages. Add your site URL in the dashboard, and the assistant answers from them. You can also add documents, and question and answer pairs.
Tip: Change the colours, the welcome message and the AI instructions in the Asyntai dashboard. The change shows in your app at once, with no new app release.
Removing It
Remove the AsyntaiAIChatbot package from your project and delete the chat code. The chat is gone from your app.
Plans & Pricing
The package is free. View pricing.
Need Help?
If you have any questions or run into issues, contact us at [email protected].