Skip to content

RevenueCat

Updated

Customers in your iOS app ask the chatbot about their own subscription, and it answers from RevenueCat: whether it is active, when it renews or ends, a payment problem, and where to manage it. Setting it up takes about ten minutes, and a little code in your app.

What your customers can ask

  • What they have: each subscription, whether it is active or in a free trial, and where they bought it.
  • When it renews or ends, and whether they turned renewal off.
  • Why access stopped: a payment that failed and is being tried again, or a subscription that ended, and when.
  • How to cancel or change it. The chatbot sends them to the store they bought it from, where they do it themselves.

It only reads. Cancelling, refunding and changing a plan stay with the store and the customer: a refund of an App Store purchase is asked of Apple. A purchase made in a test environment is called a test purchase, so you can try everything before you go live. That includes a TestFlight build's purchases, which cost the tester nothing, so a test purchase is never proof that someone paid. Dates are days in UTC.

How your app shows who is asking

The chatbot reads only the subscription of the customer your app vouches for, never one someone names in the chat: it does not ask for an email, a user id or a receipt, and does not take one. Your app shows who the customer is in one of four ways, and ChatFrom checks it on every message before anything is read.

  1. A token from your server, for customers who sign in to your app. Your server signs a short token with your chatbot's signing secret: HS256, the customer's RevenueCat app user id in sub, and an exp at most 24 hours away. Your app passes it as its user token. This works on your website too.
  2. RevenueCat's own access token, if your app signs customers in with RevenueCat's authentication, in beta at RevenueCat. Pass it as the user token instead; the chatbot checks it with your project's keys at RevenueCat.
  3. RevenueCat's anonymous id, for an app without a server of its own, once you allow it on the card. RevenueCat makes one for each customer who has not signed in, and nobody can guess one, so the app passes it as it is. Anyone who holds one can ask about that customer's subscription, as with RevenueCat's own SDK. An id you chose, such as an email or a number, could be guessed, so it always needs a token.
  4. The App Store's word, once you enter your app's bundle id on the card. The iOS SDK reads the subscriptions with StoreKit and passes on what Apple signed, which ChatFrom checks with Apple's own certificate, and it counts only for your app. The chatbot can then answer even while RevenueCat cannot be reached. It is about whoever is signed in to the App Store on the device, which is not always whoever is signed in to your app.

The last two work only in your app, where the SDK passes them. A token from your server reaches the tool servers you marked for the user token too, so a server of yours can check it with the same secret.

Your serverJavaScript
import { SignJWT } from "jose";

// On your server, never in the app: the signing secret the card showed, as the text it is.
const secret = new TextEncoder().encode(signingSecret);

// The customer's RevenueCat app user id: what your app passes to Purchases.logIn.
const userToken = await new SignJWT({})
  .setProtectedHeader({ alg: "HS256" })
  .setSubject(customer.revenueCatId)
  .setExpirationTime("1h")
  .sign(secret);
Your appSwift
// Ways 1 and 2: a token, from your server or from RevenueCat.
ChatFrom.identify(userId: user.id, userToken: userToken)

// Way 3: RevenueCat's anonymous id, for a customer who has not signed in.
ChatFrom.revenueCatAppUserId = Purchases.shared.appUserID

// Way 4: the App Store's own word on the subscriptions.
ChatFrom.sharesAppStoreSubscriptions = true

Set revenueCatAppUserId again whenever RevenueCat's id changes, as it does when someone signs in or out. ChatFrom.logout() forgets it, so set the next one after that. The iOS SDK's README has the details, and the iOS guide how to add the chat to your app.

In RevenueCat

  1. Open your project, go to API keys and press + New secret API key. Name it ChatFrom, choose V2, and give it only Customer information: Subscriptions: Read.
  2. Copy the project id from Project settings, General.

In ChatFrom

  1. Open your chatbot and go to Tools. Under Connections, tap + on RevenueCat.
  2. Paste the project id and the key, and press Connect RevenueCat. ChatFrom checks the key with RevenueCat without reading any real customer, and switches the tool on.
  3. Copy the signing secret the card shows, for your server. It is shown once. If it ever leaks, press Make a new secret: tokens signed with the old one stop working at once, and a new key keeps the secret as it is.
  4. Allow anonymous ids, or enter your app's bundle id, if your app uses those ways.
  5. In your app, open the chat while signed in and ask "When does my subscription renew?".

What stays safe

  • Your key and the signing secret are stored encrypted, and the key is never shown again. Disconnecting deletes both.
  • Who the customer is goes from the message to the tool sealed, for that conversation and that person alone, and for minutes. Nothing said in the chat can change it.
  • A token is checked on every message: one that is not signed with your secret, has run out, or runs for more than 24 hours, is refused.
  • If RevenueCat stops taking the key, the chatbot offers a hand-off, and the card asks for a new key.
  • The chatbot cannot cancel, refund or change a subscription.

To stop, switch Subscription tool off, or press Disconnect to delete the stored key and secret; then delete the key in RevenueCat too. What else a chatbot can connect to is on the Connections page.