Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Siri Shortcuts #4856

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Signal.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
06289300DC49EDEA6FEC730C /* Pods_SignalPerformanceTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C61A9604F0FC0D258C8CE27F /* Pods_SignalPerformanceTests.framework */; };
0634FE5625C71E3100D6E5EE /* SendMessage.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0634FE5525C71E3100D6E5EE /* SendMessage.intentdefinition */; };
2AE2882E4C2B96BFFF9EE27C /* Pods_SignalShareExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F94C85CB0B235DA37F68ED0 /* Pods_SignalShareExtension.framework */; };
3236FCC42592B67B006D33B9 /* NameCollisionReviewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3236FCC32592B67B006D33B9 /* NameCollisionReviewCell.swift */; };
323C4FE524EE7B0F00DC94B8 /* LinkPreviewsMegaphone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 323C4FE424EE7B0F00DC94B8 /* LinkPreviewsMegaphone.swift */; };
Expand Down Expand Up @@ -959,6 +960,7 @@

/* Begin PBXFileReference section */
02CD38E58B58A689DCF037AD /* Pods-SignalTests.app store release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalTests.app store release.xcconfig"; path = "Pods/Target Support Files/Pods-SignalTests/Pods-SignalTests.app store release.xcconfig"; sourceTree = "<group>"; };
0634FE5525C71E3100D6E5EE /* SendMessage.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = SendMessage.intentdefinition; sourceTree = "<group>"; };
0F94C85CB0B235DA37F68ED0 /* Pods_SignalShareExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SignalShareExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
10AE4264D3E52937D8964A86 /* Pods-SignalMessaging.profiling.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalMessaging.profiling.xcconfig"; path = "Pods/Target Support Files/Pods-SignalMessaging/Pods-SignalMessaging.profiling.xcconfig"; sourceTree = "<group>"; };
1BC279B87E730B066A5AFB2A /* Pods-SignalPerformanceTests.app store release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SignalPerformanceTests.app store release.xcconfig"; path = "Pods/Target Support Files/Pods-SignalPerformanceTests/Pods-SignalPerformanceTests.app store release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3253,6 +3255,7 @@
45CD81A41DBFF8CF004C9430 /* Storyboards */,
450DF2061E0DD28D003D14BE /* UserInterface */,
76EB04C818170B33006006FC /* util */,
0634FE5525C71E3100D6E5EE /* SendMessage.intentdefinition */,
);
path = src;
sourceTree = "<group>";
Expand Down Expand Up @@ -5274,6 +5277,7 @@
340FC8AB204DAC8D007AEB0F /* DomainFrontingCountryViewController.m in Sources */,
88C659B024688335002AC115 /* SelfSignedIdentity.swift in Sources */,
347C3857252E1E2300F3D941 /* CVComponentThreadDetails.swift in Sources */,
0634FE5625C71E3100D6E5EE /* SendMessage.intentdefinition in Sources */,
347C3846252CE6C900F3D941 /* CVComponentSenderName.swift in Sources */,
4C586926224FAB83003FD070 /* AVAudioSession+OWS.m in Sources */,
3470C8772555883600F5847C /* CVLoadRequest.swift in Sources */,
Expand Down
4 changes: 4 additions & 0 deletions Signal/Signal-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
<string>Signal will save photos to your library.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Signal will let you choose which photos from your library to send.</string>
<key>NSUserActivityTypes</key>
<array>
<string>SendMessageIntent</string>
</array>
<key>PHPhotoLibraryPreventAutomaticLimitedAccessAlert</key>
<true/>
<key>UIAppFonts</key>
Expand Down
25 changes: 25 additions & 0 deletions Signal/src/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#import <SignalServiceKit/TSSocketManager.h>
#import <UserNotifications/UserNotifications.h>
#import <WebRTC/WebRTC.h>
#import <Signal-Swift.h>

NSString *const AppDelegateStoryboardMain = @"Main";

Expand Down Expand Up @@ -891,6 +892,30 @@ - (BOOL)application:(UIApplication *)application
return NO;
}
return [self tryToOpenUrl:userActivity.webpageURL];
} else if ([userActivity.activityType isEqualToString:@"SendMessageIntent"]) {
OWSLogWarn(@"Executing intent %@", userActivity.activityType);

SendMessageIntent *intent = (SendMessageIntent *) userActivity.interaction.intent;

NSString *text = intent.message;
MessageBody *testMessageBody = [[MessageBody alloc] initWithText:text
ranges:MessageBodyRanges.empty];
NSString *number = [intent.recipient stringByReplacingOccurrencesOfString:@" " withString:@""];
OWSLogInfo(@"SendMessageIntent parameters: number %@ text %@", number, text);


[self.databaseStorage uiReadWithBlock:^(SDSAnyReadTransaction *transaction) {
TSThread *thread = [AnyContactThreadFinder.alloc contactThreadForPhoneNumber:number transaction:transaction];
OWSLogInfo(@"Sending message %@ to recipient %@", text, thread.recipientAddresses[0]);
TSOutgoingMessage *message = [ThreadUtil enqueueMessageWithBody:testMessageBody
thread:thread
quotedReplyModel:Nil
linkPreviewDraft:Nil
transaction:transaction];
}];

// Send message in background
return NO;
} else {
OWSLogWarn(@"userActivity: %@, but not yet supported.", userActivity.activityType);
}
Expand Down
184 changes: 184 additions & 0 deletions Signal/src/SendMessage.intentdefinition
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>tpoGz5</string>
<key>INIntentDefinitionSystemVersion</key>
<string>19E287</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>12D4e</string>
<key>INIntentDefinitionToolsVersion</key>
<string>12.4</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>share</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescription</key>
<string>Send Message to the target recipient</string>
<key>INIntentDescriptionID</key>
<string>hnvUAa</string>
<key>INIntentInput</key>
<string>message</string>
<key>INIntentLastParameterTag</key>
<integer>6</integer>
<key>INIntentManagedParameterCombinations</key>
<dict>
<key>recipient,message</key>
<dict>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Send Message</string>
<key>INIntentParameterCombinationTitleID</key>
<string>0uDpUD</string>
<key>INIntentParameterCombinationUpdatesLinked</key>
<true/>
</dict>
</dict>
<key>INIntentName</key>
<string>SendMessage</string>
<key>INIntentParameterCombinations</key>
<dict>
<key>recipient,message</key>
<dict>
<key>INIntentParameterCombinationIsLinked</key>
<true/>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<true/>
<key>INIntentParameterCombinationTitle</key>
<string>Send Message</string>
<key>INIntentParameterCombinationTitleID</key>
<string>puTSVI</string>
</dict>
</dict>
<key>INIntentParameters</key>
<array>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Message</string>
<key>INIntentParameterDisplayNameID</key>
<string>kj79D0</string>
<key>INIntentParameterDisplayPriority</key>
<integer>1</integer>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataCapitalization</key>
<string>Sentences</string>
<key>INIntentParameterMetadataDefaultValueID</key>
<string>9W8SwT</string>
<key>INIntentParameterMetadataMultiline</key>
<true/>
</dict>
<key>INIntentParameterName</key>
<string>message</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>What would you like to say?</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>wcKuBY</string>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
</array>
<key>INIntentParameterSupportsResolution</key>
<true/>
<key>INIntentParameterTag</key>
<integer>2</integer>
<key>INIntentParameterType</key>
<string>String</string>
</dict>
<dict>
<key>INIntentParameterConfigurable</key>
<true/>
<key>INIntentParameterDisplayName</key>
<string>Recipient Phone Number</string>
<key>INIntentParameterDisplayNameID</key>
<string>qEjt8p</string>
<key>INIntentParameterDisplayPriority</key>
<integer>2</integer>
<key>INIntentParameterMetadata</key>
<dict>
<key>INIntentParameterMetadataCapitalization</key>
<string>Sentences</string>
<key>INIntentParameterMetadataDefaultValueID</key>
<string>t6y1rx</string>
</dict>
<key>INIntentParameterName</key>
<string>recipient</string>
<key>INIntentParameterPromptDialogs</key>
<array>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogType</key>
<string>Configuration</string>
</dict>
<dict>
<key>INIntentParameterPromptDialogCustom</key>
<true/>
<key>INIntentParameterPromptDialogFormatString</key>
<string>Where to send the message?</string>
<key>INIntentParameterPromptDialogFormatStringID</key>
<string>bOj4Uz</string>
<key>INIntentParameterPromptDialogType</key>
<string>Primary</string>
</dict>
</array>
<key>INIntentParameterSupportsResolution</key>
<true/>
<key>INIntentParameterTag</key>
<integer>6</integer>
<key>INIntentParameterType</key>
<string>String</string>
</dict>
</array>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Send Message</string>
<key>INIntentTitleID</key>
<string>lxktYH</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Send</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>