SiriKit Sending Message

Can I send message using SiriKit or SiriKit could send messages only by using external services?


In method

handle(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void)

there is a comment saying

// Implement your application logic to send a message here.


In my case I want to send a message the same way the MFMessageComposeViewController does


Is that possible?

Accepted Reply

You Asked: "The question is: Is it possible SiriKit to send message (not email) via Messaging App."


No. SiriKit was designed for your app to send a message using your server. SiriKit was not designed to integrate with other apps such as the iOS Messages app.

Replies

If you're trying to implement sending e-mail specifically, please see this previous thread.

I would like to send a message to a phone number using Messages App via SiriKit, not an email.

In my case I would like to send a message to a phone number that does not exiss in my phone book,

that's why I am creating custom INPerson object and fill it with custom data


Everything is working, Siri detects my intent and setup hardcoded message using resolveContent method,

but once handle is executed nothing happen. Siri only response with "Message sent"


The question is: Is it possible SiriKit to send message (not email) via Messaging App.


In my case I would like to send messages to a short-code (which is paid). All short-codes will be configured in my App.


Here is the code that I am using:

import Foundation
import Intents
class MyIntent: NSObject, INSendMessageIntentHandling {

    // Implement resolution methods to provide additional information about your intent (optional).
    func resolveRecipients(for intent: INSendMessageIntent, with completion: @escaping ([INPersonResolutionResult]) -> Void) {
     
        if let recipients = intent.recipients {
            if recipients.count == 0 {
                let recipient = INPerson(personHandle: INPersonHandle(value: "1234", type: .phoneNumber, label: INPersonHandleLabel(rawValue: "PhoneNumber") ),
                                          nameComponents: nil,
                                          displayName: "CustomTitle",
                                          image: nil,
                                          contactIdentifier: nil,
                                          customIdentifier: "customIdentifier")
             
                var resolutionResults = [INPersonResolutionResult]()
                resolutionResults += [INPersonResolutionResult.success(with: recipient)]
                completion(resolutionResults)
            }
        }
    }

    func resolveContent(for intent: INSendMessageIntent, with completion: @escaping (INStringResolutionResult) -> Void) {
        completion(INStringResolutionResult.success(with: "Hello World"))
    }

    func handle(intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
        //  Implement your application logic to send a message here.
        let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
        let response = INSendMessageIntentResponse(code: .success, userActivity: userActivity)
        completion(response)
    }
}

You Asked: "The question is: Is it possible SiriKit to send message (not email) via Messaging App."


No. SiriKit was designed for your app to send a message using your server. SiriKit was not designed to integrate with other apps such as the iOS Messages app.

In your first post, I misread MFMessageComposeViewController as MFMailComposeViewController - sorry about that.


As Zaid said, this isn't possible. Siri will handle sending messages with the system's Messages app as a built in service, so there is no SiriKit API available for this.

Where may I post a few suggestions to Apple related to internal messaging system?

I would be happy iOS/watchOS to support the following thing:

- (iOS) To be able to send a message/SMS via SiriKit to contacts/persons by using predefined recipients.

- (iOS) To be able to customize UI of MFMessageComposeViewController. In some cases I don't want to open conversation composer. I want just to present a custom view to a client where he have to confirm the message he would like to send.

- (watchOS) To be able to send a message/SMS by using predefined recipients.


All suggestions are currently missing and all of them require user confirmation.

I see no reason why Apple can't add such functionality

here's the link to request an enhancement and this is also found at the bottom of this webpage and also in your developer account in the "Member Center" tab


Report Bugs

Enhancement requests via the Bug Reporter are always welcome. You should file separate requests for being able to customize the UI of the mail composer and sending messages with the built in Messages app to phone numbers with names you define but are not in Contacts.

Any solution for this??