forked from DHowett/theos-nic-templates
/
siri_command.nic
383 lines (326 loc) · 12.2 KB
/
siri_command.nic
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
nic 1
name "iphone/siri_command"
prompt AEWEBSITE "Extension/author website" "ae.k3a.me"
prompt AEDESCRIPTION "Description of the extension" "An awesome extension for Siri!"
dir Resources
file 37 Resources/Info.plist
<?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>CFBundleName</key>
<string>@@PROJECTNAME@@</string>
<key>CFBundleIdentifier</key>
<string>@@PACKAGENAME@@</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>CFBundleDisplayName</key>
<string>@@PROJECTNAME@@</string>
<key>MinimumOSVersion</key>
<string>5.0</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
</array>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>AppBundleID</key>
<string>@@PACKAGENAME@@</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>NSPrincipalClass</key>
<string>AE@@PROJECTNAME@@</string>
</dict>
</plist>
file 1 Resources/InfoPlist.strings
"@@PROJECTNAME@@" = "@@FULLPROJECTNAME@@";
file 14 AE@@PROJECTNAME@@.h
#import "SiriObjects.h"
/// Principal class - the main class of the extension
@interface AE@@PROJECTNAME@@ : NSObject<SEExtension>
-(id)initWithSystem:(id<SESystem>)system;
-(NSString*)author;
-(NSString*)name;
-(NSString*)description;
-(NSString*)website;
@end
// vim:ft=objc
file 40 AE@@PROJECTNAME@@.mm
#import "AE@@PROJECTNAME@@.h"
#import "AE@@PROJECTNAME@@Commands.h"
@implementation AE@@PROJECTNAME@@
// required initialization
-(id)initWithSystem:(id<SESystem>)system
{
if ( (self = [super init]) )
{
// register all extension classes provided
[system registerCommand:[AE@@PROJECTNAME@@Commands class]];
}
return self;
}
// optional info about extension
-(NSString*)author
{
return @"@@USER@@";
}
-(NSString*)name
{
return @"@@FULLPROJECTNAME@@";
}
-(NSString*)description
{
return @"@@AEDESCRIPTION@@";
}
-(NSString*)website
{
return @"@@AEWEBSITE@@";
}
-(NSString*)versionRequirement
{
return @"1.0.1";
}
@end
// vim:ft=objc
file 8 AE@@PROJECTNAME@@Commands.h
#import "SiriObjects.h"
@interface AE@@PROJECTNAME@@Commands : NSObject<SECommand>
-(BOOL)handleSpeech:(NSString*)text tokens:(NSArray*)tokens tokenSet:(NSSet*)tokenset context:(id<SEContext>)ctx;
@end
// vim:ft=objc
file 46 AE@@PROJECTNAME@@Commands.mm
#import "AE@@PROJECTNAME@@Commands.h"
@implementation AE@@PROJECTNAME@@Commands
-(id)init
{
if ( (self = [super init]) )
{
// additional initialization
}
return self;
}
-(void)dealloc
{
// additional cleaning
[super dealloc];
}
-(BOOL)handleSpeech:(NSString*)text tokens:(NSArray*)tokens tokenSet:(NSSet*)tokenset context:(id<SEContext>)ctx
{
// logging useful during development
// NSLog(@">> AE@@PROJECTNAME@@Commands handleSpeech: %@", text);
// react to recognized tokens (what happen or what happened)
if ([tokens count] >= 2 &&
[[tokens objectAtIndex:0] isEqualToString:@"what"] &&
( [tokenset containsObject:@"happen"] || [tokenset containsObject:@"happened"] )
)
{
// send a simple utterance response:
[ctx sendAddViewsUtteranceView:@"Somebody set up us the bomb!"];
// Inform the assistant that this is end of the request
// For more complex extensions, you can spawn an additional thread and process request asynchronly,
// ending with sending "request completed"
[ctx sendRequestCompleted];
return YES; // the command has been handled by our extension (ignore the original one from the server)
}
return NO;
}
@end
// vim:ft=objc
file 193 SiriObjects.h
//
// SiriObjects.h
// AssistantExtensions
// Version 1.0.1
//
// Created by K3A.
// Copyright (c) 2012 K3A.me. All rights reserved.
//
#pragma once
#include <Foundation/Foundation.h>
#ifdef SC_PRIVATE
# import "SiriObjects_private.h"
#endif
/// Ordinary assistant object dictionary (NSMutableDictionary) containing class name, group and properties.
typedef NSMutableDictionary SOObject;
/// Root assistant object (NSMutableDictionary). Like SOObject but with aceId and refId properties.
typedef SOObject SOAceObject;
@protocol SECommand;
/// Protocol specifying methods of context passed via handleSpeech to the class conforming to SECommand
@protocol SEContext <NSObject>
@required
/** Creates a dictionary representing an ordinary assistant object
\param className Name of the class
\param group Name of the object group
\param props Properties of the object
*/
-(SOObject*)createObjectDict:(NSString*)className group:(NSString*)group properties:(NSDictionary*)props;
/** Creates a dictionary representing utterance view
\param text A text to show and speak
*/
-(SOObject*)createAssistantUtteranceView:(NSString*)text;
/** Creates a dictionary representing utterance view
\param text A text to show
\param speakableText A text to speak
*/
-(SOObject*)createAssistantUtteranceView:(NSString*)text speakableText:(NSString*)speakableText;
/** Creates a dictionary representing utterance view
\param text A text to show
\param speakableText A text to speak
\param dialogIdentifier Dialog identifier
*/
-(SOObject*)createAssistantUtteranceView:(NSString*)text speakableText:(NSString*)speakableText dialogIdentifier:(NSString*)dialogIdentifier;
/** Creates a dictionary representing a snippet
\param snippetClass Name of the snippet class
\param props Dictionary of snippet properties
*/
-(SOObject*)createSnippet:(NSString*)snippetClass properties:(NSDictionary*)props;
/** Sends a root assistant object
*/
-(BOOL)sendAceObject:(NSString*)className group:(NSString*)group properties:(NSDictionary*)props;
/** Sends "request completed" to the assistant
*/
-(BOOL)sendRequestCompleted;
/** Sends views to the assistant
\param views Array of views to send
*/
-(BOOL)sendAddViews:(NSArray*)views;
/** Sends views to the assistant
\param views Array of views to send
\param dialogPhase Dialog phase, e.g. Reflection (will be replaced), Completion, Summary, Clarification, Error, Acknowledgement
\param scrollToTop Should scroll to top
\param temporary Temporary flag
*/
-(BOOL)sendAddViews:(NSArray*)views dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary;
/** Create a snippet and send it immediately
\param snippetClass Name of the snippet class
\param props Properties for the snippet class
*/
-(BOOL)sendAddViewsSnippet:(NSString*)snippetClass properties:(NSDictionary*)props;
/** Create a snippet and send it immediately
\param snippetClass Name of the snippet class
\param properties Properties for the snippet class
\param dialogPhase Dialog phase, e.g. Reflection (will be replaced), Completion, Summary, Clarification, Error, Acknowledgement
\param scrollToTop Should scroll to top
\param temporary Temporary flag
*/
-(BOOL)sendAddViewsSnippet:(NSString*)snippetClass properties:(NSDictionary*)props dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary;
/** Create utterance (text) and send it immediately
\param text Text to send
*/
-(BOOL)sendAddViewsUtteranceView:(NSString*)text;
/** Create utterance (text) and send it immediately
\param text Text to send
\param speakableText Text to speak (different from what is displayed)
*/
-(BOOL)sendAddViewsUtteranceView:(NSString*)text speakableText:(NSString*)speakableText;
/** Create utterance (text) and send it immediately
\param text Text to send
\param speakableText Text to speak (different from what is displayed)
\param dialogPhase Dialog phase, e.g. Reflection (will be replaced), Completion, Summary, Clarification, Error, Acknowledgement
*/
-(BOOL)sendAddViewsUtteranceView:(NSString*)text speakableText:(NSString*)speakableText dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary;
/** Create utterance (text) and send it immediately
\param text Text to send
\param speakableText Text to speak (different from what is displayed)
\param dialogPhase Dialog phase, e.g. Reflection (will be replaced), Completion, Summary, Clarification, Error, Acknowledgement
*/
-(BOOL)sendAddViewsUtteranceView:(NSString*)text speakableText:(NSString*)speakableText dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary;
/** Create utterance (text) and send it immediately
\param text Text to send
\param speakableText Text to speak (different from what is displayed)
\param dialogPhase Dialog phase, e.g. Reflection (will be replaced), Completion, Summary, Clarification, Error, Acknowledgement
\param listen Whether to listen for user response just after speaking the text. If YES, next request will be sent to the same SECommand.
\since 1.0.1
*/
-(BOOL)sendAddViewsUtteranceView:(NSString*)text speakableText:(NSString*)speakableText dialogPhase:(NSString*)dialogPhase scrollToTop:(BOOL)scrollToTop temporary:(BOOL)temporary listenAfterSpeaking:(BOOL)listen; //SINCE 1.0.1
/** Returns a boolean indicating whether the current request has been completed (by calling sendRequestCompleted). */
-(BOOL)requestHasCompleted;
/** Returns an object which handled the request or nil if the request has not been handled yet. */
-(NSObject<SECommand>*)object;
/** Returns a string with refId of the current request. */
-(NSString*)refId;
@end
/** Protocol specifying methods of an extension class representing snippet.
Instances of these classes will be created for every snippet creation request.
A class representing snippet can derive from UIView or just represent some proxy class creating it's UIView on demand.
Don't forget you really should prefix your class with some shortcut, e.g. K3AAwesomeSnippet!
*/
@protocol SESnippet <NSObject>
@required
/// Initializes a snippet by properties
-(id)initWithProperties:(NSDictionary*)props;
/// Returns a view representing snippet, can be self if the conforming class is already UIView
-(id)view;
@end
/** Protocol specifying methods of an extension class handling commands.
Classes conforming to this protocol are initialized just after loading bundle and will remain in memory.
Don't forget you really should prefix your class with some shortcut, e.g. K3AAwesomeCommand!
*/
@protocol SECommand <NSObject>
@required
/** Allows the extension to react to recognized text.
\param text Recognized text
\param tokens An ordered array of lowercase tokens representing recognized words
\param tokenset An unordered set of tokens for fast search - recommended parameter for keyword-matching
\param ctx Context representing the current request also allowing to send responses
*/
-(BOOL)handleSpeech:(NSString*)text tokens:(NSArray*)tokens tokenSet:(NSSet*)tokenset context:(id<SEContext>)ctx;
@end
/** Protocol specifying methods for the NSPrincipal class of the extension.
*/
@protocol SESystem <NSObject>
@required
/// Register a command class
-(BOOL)registerCommand:(Class)cls;
/// Register a snippet class
-(BOOL)registerSnippet:(Class)cls;
/// Returns the version string of AssistantExtensions
-(NSString*)systemVersion; //SINCE 1.0.1
@end
/// Protocol specifying methods of the extension's principal class
@protocol SEExtension <NSObject>
@required
/// The first method which is called on your class, system is where you register commands and snippets
-(id)initWithSystem:(id<SESystem>)system;
@optional
/// Extension author
-(NSString*)author;
/// Extension name
-(NSString*)name;
/// Extension description
-(NSString*)description;
/// Extension website URL
-(NSString*)website;
/// Minimal SiriExtensions version requirement
-(NSString*)versionRequirement; //SINCE 1.0.1
@end
// vim:ft=objc
file 12 Makefile
include theos/makefiles/common.mk
BUNDLE_NAME = @@PROJECTNAME@@
@@PROJECTNAME@@_BUNDLE_EXTENSION = assistantExtension
@@PROJECTNAME@@_FILES = AE@@PROJECTNAME@@.mm AE@@PROJECTNAME@@Commands.mm
@@PROJECTNAME@@_INSTALL_PATH = /Library/AssistantExtensions/
@@PROJECTNAME@@_FRAMEWORKS = UIKit CoreGraphics
include $(THEOS_MAKE_PATH)/bundle.mk
after-install::
install.exec "killall -9 SpringBoard"
file 9 control
Package: @@PACKAGENAME@@
Name: @@FULLPROJECTNAME@@
Depends: firmware (>= 5.0), gsc.assistant | com.chpwn.spire, me.k3a.ae
Version: 0.0.1
Architecture: iphoneos-arm
Description: @@AEDESCRIPTION@@
Maintainer: @@USER@@
Author: @@USER@@
Section: Addons (AssistantExtensions)