Article

Starting a Chat from your App

Let customers start a conversation with you from your app.

Overview

You can let a customer start a chat from your app by creating a class button and adding it to the app’s user interface. Build the chat button so that it calls the Business Chat URL link used in the target-action mechanism to initiate a conversation with your business when the customer taps the button.

Use the SVG button images to create a Business Chat button class. The SVG images are customizable to meet your design needs. Make sure you use an appropriate call-to-action message so your customers know that they can get resolution to their questions by tapping this entry point. For more information about customizing the Business Chat button for your website or app, see Business Chat Human Interface Guidelines.

The sample code below shows how to verify iOS version compatibility and build the Business Chat URL link with intent parameters.

Listing 1

An example of adding a Business Chat button to a view.

@IBOutlet weak var chatButton: UIButton!
  override func viewDidLoad() {
    super.viewDidLoad()
     // Check to see if device iOS version is supported
     // Hide chat button if device is not supported
    if #available(iOS 11.3, *){
      chatButton.isHidden = false
    } 
    else {
      chatButton.isHidden = true
    }
  }

  func BCUrlConstructor (intentId: String, groupId: String, bodyParam: String) -> URL {
    let bizId = "" // Sets the Business ID
     // Construct Business Chat URL using business ID, intent ID, group ID, and preset body text
    let url : NSString = "https://bcrw.apple.com/sms:open?service=iMessage&recipient=urn:biz:\(bizId)&biz-intent-id=\(intentId)&bizgroup-id=\(groupId)&body=\(bodyParam)" as NSString
    let urlString : NSString = url.addingPercentEncoding(withAllowedCharacters:NSCharacterSet.urlQueryAllowed)! as NSString
    let bcUrl : NSURL = NSURL(string: urlString as String)!
    return bcUrl as URL
    }

@IBAction func chatButtonTap(_ sender: Any) {
     //Send Intent parameters to construct Business Chat URL
    let url = BCUrlConstructor(intentId: “INTENTID", groupId: “GROUPID", bodyParam: “PRESET TEXT")
     // Launch Business Chat
    UIApplication.shared.open(url)
    }

Topics

Routing Values

About Intent, Group, and Body Values

Prioritize and route messages by defining intent, group, and body values.

See Also

Chat with Customers

Adding a Business Chat Button to Your Website

Let customers start a conversation with you by adding a Business Chat button to your website.

Starting a Chat from a URL

Let customers start a conversation with you from your website or email message.

Business and Place Cards

Allow customers to contact your business from Maps, Siri, and Spotlight searches.