Best approach for writing Siri “handsfree” Intent handler with a Meteor Cordova app?

Hi, I am trying to workout the best approach for writing a SiriIntent handler so I could do something like "Hey Siri, send a message using "

background: running on Meteor 1.4.4.1 and an iOS Swift newer than newbee (no SWIFT experience)

The key requirement here is for handsfree use of the app. So, I think, the approach would be to use the Sirikit messaging intent https://developer.apple.com/library/content/documentation/Intents/Conceptual/SiriIntegrationGuide/SiriDomains.html#//apple_ref/doc/uid/TP40016875-CH9-SW2

I have added an intent target, as per documentation where generates an intent handler which includes the following code:

 // Implement resolution methods to provide additional information about your intent (optional).
    func resolveRecipients(forSendMessage intent: INSendMessageIntent, with completion: @escaping ([INPersonResolutionResult]) -> Void) {
        print("Hello, world")
        if let recipients = intent.recipients {
            
            // If no recipients were provided we'll need to prompt for a value.
            if recipients.count == 0 {
                completion([INPersonResolutionResult.needsValue()])
                return
            }
    
            var resolutionResults = [INPersonResolutionResult]()
            for recipient in recipients {
                let matchingContacts = [recipient] // Implement your contact matching logic here to create an array of matching contacts
                switch matchingContacts.count {
                case 2  ... Int.max:
                    // We need Siri's help to ask user to pick one from the matches.
                    resolutionResults += [INPersonResolutionResult.disambiguation(with: matchingContacts)]
                    
                case 1:
                    // We have exactly one matching contact
                    resolutionResults += [INPersonResolutionResult.success(with: recipient)]
                    
                case 0:
                    // We have no contacts matching the description provided
                    resolutionResults += [INPersonResolutionResult.unsupported()]
                    
                default:
                    break
                    
                }
            }
            completion(resolutionResults)
        }
    }

So, I am thinking I’d use either https://github.com/martijnwalraven/meteor-ios or https://github.com/siegesmund/SwiftDDP to do a call to Meteor and get my list of recipients and then somehow format them so that Siri understands that they’re contacts.

Siri would then capture my message (voice to text) and then when I send, I am guessing I just make a Meteor method call… ie insert some meteor DDP “stuff” in here:

// Once resolution is completed, perform validation on the intent and provide confirmation (optional).
    
    func confirm(sendMessage intent: INSendMessageIntent, completion: @escaping (INSendMessageIntentResponse) -> Void) {
        // Verify user is authenticated and your app is ready to send a message.
        
        let userActivity = NSUserActivity(activityType: NSStringFromClass(INSendMessageIntent.self))
        let response = INSendMessageIntentResponse(code: .ready, userActivity: userActivity)
        completion(response)
    }
    
    // Handle the completed intent (required).
    
    func handle(sendMessage 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)
    }

Any thoughts recommendations, please?
Anyone done anything similar?
@martijnwalraven @peter1

1 Like