Skip to content

Instantly share code, notes, and snippets.

@shakked
Created September 21, 2022 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shakked/c6e1de1bb91b03d9ddf770ed39bf84d9 to your computer and use it in GitHub Desktop.
Save shakked/c6e1de1bb91b03d9ddf770ed39bf84d9 to your computer and use it in GitHub Desktop.
ChatKit Examples
class Example {
static let cardpointers: [Chat] = [
ChatMessage("Hey, this is Emmanuel, the founder of CardPointers!"),
ChatMessage("So I noticed you've been using the app quite a bit!"),
ChatMessageConditional("Can I borrow literally 60 seconds of your time, just wanted to ask you a quick question...", options: [
ChatOption("Sure", chats: [
ChatMessageConditional("Have you been enjoying CardPointers?", options: [
ChatOption("Yes!", chats: [
ChatMessage("Wow! So glad to hear it! That makes me so happy. If I'm being honest, we've been getting some 1-star reviews lately."),
ChatMessage("Okay, tiny favor to ask, but it would make such a huge difference."),
ChatMessage("Would you mind writing a few words about your experience with CardPointers as a review on the App Store?"),
ChatMessage("I know, it's annoying, but it really makes a *huge* difference."),
ChatMessageConditional("What do you say?", options: [
ChatOption("Sure!", chats: [
ChatMessage("You are amazing."),
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Let me open that page for you right now..."),
ChatOpenURL(url: URL(string: "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=1472875808&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software&action=write-review")!, withSafariVC: false),
ChatShowCancelButton(),
]),
ChatOption("Of Course!", chats: [
ChatMessage("You are amazing."),
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Let me open that page for you right now..."),
ChatOpenURL(url: URL(string: "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=1472875808&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software")!, withSafariVC: false),
ChatShowCancelButton(),
]),
ChatOption("Not Now", chats: [
ChatMessage("Ok, I understand that's a big ask."),
ChatMessage("I'm going to show the rating prompt instead which is super quick."),
ChatRunLogic(block: { target in
SKStoreReviewController.requestReview()
}),
ChatMessage("Anyway, have the best day!"),
ChatShowCancelButton()
])
])
]),
ChatOption("It's Okay", chats: [
ChatMessage("Glad to hear you're finding it okay."),
ChatMessage("This app is my livelihood, and I care about it so much."),
ChatMessage("I'd appreciate if you could tell me how I could improve it..."),
ChatMessageConditional("Here's a super short survey, whatever you write here I'll read immediately and start working on fixing! I promise.", options: [
ChatOption("Answer Survey", chats: [
ChatFallingEmojis(emoji: "💳"),
ChatMessage("You're the best!"),
ChatOpenURL(url: URL(string: "https://www.typeform.com/")!),
ChatShowCancelButton()
]),
ChatOption("Not Now", chats: [
ChatMessage("No problem, have a great day!"),
ChatShowCancelButton()
])
])
]),
ChatOption("Nope", chats: [
ChatMessage("Oh, I'm so sorry to hear that."),
ChatMessage("This app is my livelihood, and I care about it so much."),
ChatMessage("I'd appreciate if you could tell me how I could improve it..."),
ChatMessageConditional("Here's a super short survey, whatever you write here I'll read immediately and start working on fixing! I promise.", options: [
ChatOption("Answer Survey", chats: [
ChatMessage("You're the best!"),
ChatOpenURL(url: URL(string: "https://www.typeform.com/")!),
ChatShowCancelButton()
]),
ChatOption("Not Now", chats: [
ChatMessage("No problem, have a great day!"),
ChatShowCancelButton()
])
])
])
])
]),
ChatOption("Nope", chats: [
ChatMessage("Ah ok, no problem. I'll let you get back to using the app!"),
ChatShowCancelButton()
])
])
]
static let cardpointersSubscribe: [Chat] = [
ChatMessage("Hey, this is Emmanuel, the founder of CardPointers!"),
ChatMessage("I noticed you haven't claimed you free trial of CardPointers Pro."),
ChatMessage("Just so you know, it's a 100% free trial and we have excellent billing policies."),
ChatMessage("So at any point if you want to cancel or get a refund, we have your back."),
ChatMessageConditional("Want to give it a try?", options: [
ChatOption("Sure!", chats: [
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Enjoy"),
ChatMessage("Purchasing..."),
ChatDelay(3.0),
ChatMessage("Welcome to Pro!"),
]),
ChatOption("No Thanks", chats: [
ChatMessageConditional("If you don't mind, I'm just curious why you're not interested. (I'm always trying to improve the app, this is my job after all!)", options: [
ChatOption("Too Expensive", chats: [
ChatMessage("I totally get that. Well hey, I have an idea. Why don't I give you a 40% off discount?"),
ChatMessage("Just do me a favor, promise not to tell anyone."),
ChatMessage("This will be our little secret..."),
ChatMessageConditional(options: [
ChatOption("Claim 40% Discount", chats: [
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Enjoy"),
ChatMessage("Purchasing..."),
ChatDelay(3.0),
ChatMessage("Welcome to Pro!"),
]),
ChatOption("Skip", chats: [
ChatMessage("Ah, I'm sad to see that."),
ChatMessage("What would be a reasonable price for CardPointers Pro where you'd consider buying it?"),
ChatMessageConditional(options: [
ChatOption("Submit Price", chats: [
ChatOpenURL(url: URL(string: "https://www.typeform.com/")!)
])
])
])
])
]),
ChatOption("Not Useful", chats: [
ChatMessage("Are you sure?"),
ChatMessage("One of my favorite features is the credit card wizard, which allows you to see exactly which card you should be using for every dollar you spend."),
ChatMessage("If you spend a decent amount per month, this alone could cover your CardPointers Pro subscription."),
ChatMessage("On Pro, we even have a Safari Extension which follows you to websites and advises you on which card to use!"),
ChatMessage("Hey, that's kind of hard to beat."),
ChatMessageConditional("So, want to try Pro out?", options: [
ChatOption("Sure!", chats: [
ChatMessage("You are the best."),
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Let me get that transaction started for you..."),
ChatMessage("Purchasing..."),
ChatDelay(3.0),
ChatMessage("Welcome to Pro!"),
]),
ChatOption("No, sorry :(", chats: [
ChatMessage("Ah, that's okay. I totally get it."),
ChatMessage("One last thing, I can give you a 40% discount right now, you seem like a nice person."),
ChatMessageConditional("Want to try it out?", options: [
ChatOption("Yes!", chats: [
ChatMessage("Great!"),
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Let me get that transaction started for you..."),
ChatMessage("Purchasing..."),
ChatDelay(3.0),
ChatMessage("Welcome to Pro!"),
]),
ChatOption("Nope :(", chats: [
ChatMessage("No worries! Feel free to keep using the app for free :)"),
])
])
])
])
]),
ChatOption("Other", chats: [
ChatMessageConditional("Hm... mind telling me why? I want to work on the app and improve it :)", options: [
ChatOption("Sure", chats: [
ChatMessage("Thank you so much."),
ChatMessage("Just going to ask you a few quick questions..."),
ChatOpenURL(url: URL(string: "https://www.typeform.com/")!),
ChatMessage("I really appreciate you taking the time to fill out that survey."),
ChatMessage("As a token of my gratitude, here's a 40% discount on Pro!"),
ChatMessageConditional(options: [
ChatOption("Claim 40% Discount", chats: [
ChatMessage("Here you go!"),
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Let me get that transaction started for you..."),
ChatMessage("Purchasing..."),
ChatDelay(3.0),
ChatMessage("Welcome to Pro!"),
]),
ChatOption("Discard Discount", chats: [
ChatMessage("Thanks for your time!"),
])
])
]),
ChatOption("Not Right Now", chats: [
ChatMessage("No problem at all."),
ChatMessage("Last thing I'll bug you with. I know you're busy, but any interested in a 40% discount on Pro?"),
ChatMessageConditional("Just say the word and I'll unlock it!", options: [
ChatOption("Yes", chats: [
ChatMessage("Great!"),
ChatFallingEmojis(emoji: "💳"),
ChatMessage("Let me get that transaction started for you..."),
ChatMessage("Purchasing..."),
ChatDelay(3.0),
ChatMessage("Welcome to Pro!"),
]),
ChatOption("No", chats: [
ChatMessage("Thanks for your time!"),
])
])
])
]),
])
])
])
]),
ChatShowCancelButton()
]
static let flighty: [Chat] = [
]
static let chats: [Chat] = [
ChatMessageConditional("How's are you today?", options: [
ChatOption("Good", chats: [
ChatMessage("I'm glad to hear you are good!"),
]),
ChatOption("Bad", chats: [
ChatMessage("I'm sorry to hear that."),
ChatMessageConditional("Can I offer you some ice cream to make you feel better?", options: [
ChatOption("Sure", chats: [
ChatMessage("Great, here you go 🍦"),
ChatMessage("I hope that helps."),
]),
ChatOption("I'm Okay.", chats: [
ChatMessage("If there's anything I can do to help, just let me know!"),
])
])
]),
ChatOption("Bad", chats: [
]),
]),
ChatFallingEmojis(emoji: "😀")
]
static var hashtagExpertSupportFlow: [Chat] {
let anythingElse: ChatMessageConditional = ChatMessageConditional("Is there anything else I can help you with?", options: [
ChatOption("Yes", chats: [
ChatLoopEnd(id: "support"),
]),
ChatOption("Nope :)", chats: [
ChatFallingEmojis(emoji: "😄"),
ChatMessage("Ok great! Glad I was able to help you."),
ChatMessage("If there's anything else, you can always come right back here."),
ChatMessage("Have a great day!"),
ChatDismiss(after: 3.0),
])
])
let contactSupport: [Chat] = [
ChatMessage("Sorry I wasn't able to directly answer your question."),
ChatMessage("Let me put you in touch with support directly so you can ask them."),
ChatOpenURL(url: URL(string: "https://command-services.typeform.com/c/RJxRZ4e6")!),
]
let chats: [Chat] = [
ChatMessage("Hey, welcome to support."),
ChatLoopStart(id: "support"),
ChatRandomMessage(["What can I help you with today?", "Which of these can I help you with?", "Here are a few topics:", "Here are some things I can help you with:"]),
ChatMessageConditional(options: [
ChatOption("Billing & Subscriptions", chats: [
ChatMessage("Sure! No problem."),
ChatMessageConditional("Which of these applies?", options: [
ChatOption("Manage Subscription", chats: [
ChatMessage("Sure, let me open that up for you."),
ChatOpenURL(url: URL(string: "https://apps.apple.com/account/subscriptions")!, withSafariVC: false),
]),
ChatOption("Subscription Status", chats: [
ChatMessage("Sure, let me check on that for you..."),
ChatDelay(3.0),
ChatMessage("Aha, you have a Pro subscription that expires in 29 days. You don't have auto-renew turned on.")
]),
ChatOption("Restore Purchases", chats: [
ChatMessage("One moment..."),
ChatDelay(2.0),
ChatMessage("Your purchases have been restored!"),
ChatFallingEmojis(emoji: "💸"),
]),
ChatOption("Cancel Subscription", chats: [
ChatMessageConditional("Mind if I ask you a few questions about why you're cancelling? (I'll be quick, I promise)", options: [
ChatOption("Sure", chats: [
ChatMessage("You're a lifessaver!"),
ChatMessageConditional("Ok, why are you cancelling?", options: [
ChatOption("Too Expensive", chats: []),
ChatOption("Not Useful", chats: []),
ChatOption("It Doesn't Work", chats: []),
ChatOption("Other", chats: []),
]),
ChatMessage("Thank you so much. That tiny bit of feedback will help us improve the app."),
ChatMessage("Let me redirect you to cancel."),
ChatOpenURL(url: URL(string: "https://apps.apple.com/account/subscriptions")!, withSafariVC: false)
]),
ChatOption("No", chats: [
ChatMessage("Absolutely, let me take you to the cancel page."),
ChatOpenURL(url: URL(string: "https://apps.apple.com/account/subscriptions")!, withSafariVC: false)
])
])
]),
ChatOption("Refunds", chats: [
ChatMessage("Oh no, I'm so sorry you got charged. We're going to help you get your money back ASAP."),
ChatMessage("I'm going to open up the refund request form for you now..."),
ChatMessage("Simply mark the transaction from Hashtag Expert you'd like to get refunded and it should be back in a few days."),
ChatMessage("If not, come back here and we'll help you out."),
ChatOpenURL(url: URL(string: "https://reportaproblem.apple.com")!, withSafariVC: false)
]),
]),
anythingElse
]),
ChatOption("Hashtags & Tutorials", chats: [
ChatMessageConditional("Sure, here are a couple topics I can help you with:", options: [
ChatOption("Generating Hashtags", chats: [
ChatMessage("Here's a super helpful article on %@."),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/tutorials/how-to-generate-a-group-of-hashtags")!)
]),
ChatOption("How to Pick Hashtags", chats: [
ChatMessage("Ah, I wrote this really helpful article about that. Check it out."),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/tutorials/the-four-rules-of-hashtags")!)
]),
ChatOption("Trending Tab", chats: [
ChatMessage("No prob! Here's how to use the trending tab."),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/tutorials/trending-hashtags")!)
]),
ChatOption("Collections", chats: [
ChatMessage("Collections are super cool. Let me show you how to use them."),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/tutorials/collections-app-feature-hashtag-expert")!)
]),
ChatOption("All Articles", chats: [
ChatMessage("We have a bunch of great resources!"),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/tutorials")!)
]),
ChatOption("Other", chats: contactSupport),
]),
anythingElse
]),
ChatOption("Instagram", chats: [
ChatMessage("We have a lot of super helpful resources on how to use Instagram effectively."),
ChatMessageConditional("Want me to show you them?", options: [
ChatOption("Yes", chats: [
ChatMessage("Ah, I wrote this really helpful article about that. Check it out."),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/tutorials/the-four-rules-of-hashtags")!)
]),
ChatOption("Nope", chats: [
anythingElse
]),
ChatOption("Other", chats: contactSupport),
]),
]),
ChatOption("Connect Facebook Account", chats: [
ChatMessage("Connecting your Facebook account to Hashtag Expert is a great way to get advanced analytics."),
ChatMessage("We admit, they don't make it easy and it can be a bit confusing."),
ChatMessage("Let me help you out a bit"),
ChatMessage("So basically, you need to make sure that your Instagram account is a business or creator account. Then, it must be connected to a corresponding Facebook page."),
ChatMessage("Then, in Hashtag Expert, you log in using THAT Facebook account."),
ChatMessage("This will allow us to show you more personalized hashtags, your best time to post, and other analytics in the app."),
ChatMessageConditional("Did that answer your question or are you still having issues?", options: [
ChatOption("Yes", chats: [
ChatMessage("Fantastic!"),
]),
ChatOption("No", chats: [
ChatMessage("Dang. Sorry about that. Here's a link to our FAQs which has more helpful info."),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/faq")!),
]),
ChatOption("Contact Support", chats: contactSupport),
]),
anythingElse
]),
ChatOption("FAQs", chats: [
ChatMessage("We have a great FAQ."),
ChatMessage("Let me take you there"),
ChatOpenURL(url: URL(string: "https://www.hashtag.expert/faq")!),
anythingElse
]),
ChatOption("Other", chats: [
ChatMessage("Let me put you in touch with a support agent."),
ChatMessage("One moment..."),
ChatOpenURL(url: URL(string: "https://command-services.typeform.com/c/RJxRZ4e6")!),
anythingElse
]),
]),
]
return chats
}
static let reviews: [Chat] = [
ChatMessage("Hey John, how are ya!"),
ChatMessage("This is Zach, the founder of ChatKit."),
ChatMessageConditional("I have a quick question for you, do you have a minute?", options: [
ChatOption("Sure", chats: [
ChatMessage("Okay, so recently, we've been getting some 1 star reviews on the app."),
ChatMessage("It really stinks, I try so hard to get good ratings, but it just doesn't work!"),
ChatMessageConditional("You ever try really hard and still not get something?", options: [
ChatOption("Yes, I understand", chats: [
ChatMessage("Exactly!")
]),
ChatOption("No, you are crazy.", chats: [
ChatMessage("Lol. Maybe a little")
])
]),
ChatMessage("So here's my question..."),
ChatMessageConditional("Can you take 2 minutes out of your day to write us a review?", options: [
ChatOption("Sure", chats: [
ChatMessage("Omg. You are a lifesaver!"),
ChatMessage("Here's the link, thank you so much!"),
ChatButton(title: "Write Review", image: UIImage(systemName: "square.and.pencil")!, tapped: { _ in
if let url = URL(string: "itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=1256222789&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
})
]),
ChatOption("No, I'm busy", chats: [
ChatMessage("Aha, I totally get that. Let me let you out of here so you can get back to your life."),
ChatMessage("... where is that darn button"),
ChatMessage("There it is!"),
ChatShowCancelButton()
])
])
]),
ChatOption("Nope", chats: [
ChatMessage("Ah okay, no problem. I'll let you get back to it."),
ChatMessage("Let me toggle that darn dismiss button for you..."),
ChatShowCancelButton(),
ChatMessage("There it is. Half a great day!"),
ChatFallingEmojis(emoji: "😄")
])
])
]
static let survey: [Chat] = [
ChatMessage("Hey Paul, this is Zach, the founder of ChatKit."),
ChatUserMessage("Hey Zach, this is Paul... a user of ChatKit"),
ChatMessage("Ah, hello there good friend!"),
ChatMessage("Now, you're probably wondering why I brought you here."),
ChatUserMessage("I could not be less curious about why you brought me here."),
ChatMessage("Yes yes, with patience, you shall learn."),
ChatMessage("Well, it's simple. I'm trying to figure out ..."),
ChatMessage("I'm embarrassed to say it."),
ChatMessageConditional(options: [
ChatOption("Spit it out", chats: [
ChatMessage("Ah! Fine.")
]),
ChatOption("Don't be embarrassed", chats: [
ChatMessage("Oh shucks, I will. You're a good person.")
]),
]),
ChatMessage("Well, I'm trying to figure out how much to charge for my app."),
ChatMessage("Accordingy to my *fancy* data, you are a paying user."),
ChatMessageConditional("Are you?", options: [
ChatOption("Yes, I pay", chats: [
ChatMessage("Wow, thank you for your support!"),
ChatMessage("Okay, can I borrow two mintues of your time?"),
ChatMessageConditional(options: [
ChatOption("Lol. No.", chats: [
ChatMessage("Fine. No need to be sassy. Feel free to leave!"),
ChatShowCancelButton()
]),
ChatOption("Sure!", chats: [
ChatMessage("Ah, thank you so much, you are a lifesaver!"),
ChatMessage("So here's a quick survey, it only has 3 questions."),
ChatMessage("It would help me so much if you filled this out."),
ChatButton(title: "Open Survey", image: UIImage(systemName: "checkmark.circle.fill")!, tapped: { controller in
if let url = URL(string: "https://www.typeform.com/") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}),
ChatMessage("Thank you so much!"),
ChatShowCancelButton(),
])
])
]),
ChatOption("No, I do not pay", chats: [
ChatMessage("Ah, it appears there has been a mistake."),
ChatMessage("You are free to go!"),
ChatShowCancelButton(),
]),
])
]
static let support: [Chat] = [ChatMessage("Hey, I'm Zach, a customer support agent."),
ChatMessage("I'm going to do my best to help you."),
ChatLoopStart(id: "loop"),
ChatMessageConditional("Which of these applies?", options: [
ChatOption("Refunds", chats: [
ChatRunLogic(block: { _ in
// UIApplication.shared.open(URL(string: "https://apps.apple.com/us/app/hashtag-expert/id1256222789")!)
}),
ChatFallingEmojis(emoji: "💸")
]),
ChatOption("Tech Support", chats: [
ChatMessageConditional("Where are you having technical problems?", options: [
ChatOption("App", chats: [
ChatMessage("Aha. Here's a support article"),
ChatButton(title: "Open Article", image: nil, tapped: { _ in
// open article
})
]),
ChatOption("Website", chats: [
ChatMessage("Let me direct you to our FAQs.."),
ChatButton(title: "Open FAQs", image: nil, tapped: { _ in
// open FAQs
})
]),
ChatOption("Watch App", chats: [
ChatMessage("We actually don't have a Watch app yet, interested in the beta?"),
ChatMessageConditional("", options: [
ChatOption("Yes", chats: [
ChatRunLogic(block: { _ in
// open up typeform to put name on list
})
]),
ChatOption("Nope!", chats: [
ChatMessage("Aha, I totally get that")
])
])
]),
]),
]),
ChatOption("Get in Touch", chats: [
ChatMessageConditional("How do you want to contact us?", options: [
ChatOption("Email", chats: [
ChatMessage("Sure, I'll open up that UI for you."),
ChatRunLogic(block: { _ in
// open email UI
})
]),
ChatOption("Call", chats: [
ChatMessage("Great. Our number is 1800-555-5555."),
ChatMessage("I'll start the call for you."),
ChatRunLogic(block: { _ in
// start the call
})
])
])
])
]),
ChatMessageConditional("Is there anything else I can help you with?", options: [
ChatOption("Yes", chats: [
ChatLoopEnd(id: "loop")
]),
ChatOption("No", chats: [
ChatMessage("Okay, have a great day!"),
])
]),
ChatFallingEmojis(emoji: "🔥"),
ChatDismiss(after: 10.0)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment