Adding Quack AI to your Swift app
This is a simple guide to adding the Quack AI Chatbot to your iOS/Swift app. Broadly, all we need to do is display a WebView
pointing to your custom company URL where you want the chatbot to appear.
Step 1:
Make sure you have the WebKit framework installed. If not, here's how you do it:
In Xcode, click on your project in the Project Navigator.
Select your app's target.
In the tab bar, click on
General
.Scroll down to the
Frameworks, Libraries, and Embedded Content
section.Click the
+
button and search forWebKit.framework
. Add it to your project.
Step 2:
Set up your WebView
. You can do this many ways, but here's an example of creating a UIViewRepresentable
wrapper for WKWebView
:
Step 3:
Display the WebView
where you want your chatbot interface to appear, and point it to your URL. Here's an example of displaying the chatbot in a drawer that slides up when you tap a button:
That's it. You're done!
Step 4 (Optional):
If you want to pass in user ID and metadata, simply add them on as URL params, like so:
This metadata will be saved along with each conversation. User ID is what unique identifies a user and allows conversation history to be saved across sessions.
Step 5 (Optional):
If you want to enable authentication for your users, you may pass in your authentication signature and epoch via the HTTP Headers. See here for more info.
Push Notifications
To set up push notifications, you should follow these steps:
Step 1:
Securely share your Apple key id
, bundle id
, and .p8 certificate
with your Quack Account Manager.
Step 2:
Pass in the user's device token via metadata as ios_device_token
. You should do this as specified above, like:
And you're all set! Push notifications will now be sent to the user's device when new messages are sent when the user does not have the chat interface open.
Get Unread Messages Per User
To fetch the unread messages for a user (to display as a badge or indicator), we expose an external REST API that simple returns the total number of unread messages.
Params:
token
: Your company's unique API keyuser_id
: The ID of the user who's unread message count you'd like to look up
Example with curl:
The response will be of the form:
Last updated