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)
}
}