Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 5422e3a

Browse files
adamcohenroseFleker
authored andcommitted
Additional modes (#39)
* Detect and handle SIGN_IN intent * Detect and handle NEW_SURFACE intent
1 parent 3382fc4 commit 5422e3a

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed

src/actions-on-google.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ i18n.configure({
4747
defaultLocale: DEFAULT_LOCALE,
4848
})
4949

50+
const INTENT_NAMES = {
51+
NEW_SURFACE: 'actions.intent.NEW_SURFACE',
52+
SIGN_IN: 'actions.intent.SIGN_IN',
53+
}
54+
5055
const PROTO_ROOT_DIR = protoFiles.getProtoPath('..')
5156
const embeddedAssistantPb = grpc.load({
5257
root: PROTO_ROOT_DIR,
@@ -232,7 +237,13 @@ export interface AssistResponse {
232237
headers: string[],
233238
rows: AssistResponseTableRow[],
234239
}
240+
newSurface?: {
241+
capabilities: string[],
242+
context: string,
243+
notificationTitle: string,
244+
}
235245
deviceAction?: string
246+
signInIntent?: boolean
236247
}
237248

238249
/**
@@ -531,6 +542,12 @@ export class ActionsOnGoogle {
531542
if (possibleIntents) {
532543
const possibleIntent = possibleIntents[0]
533544
const inputValueData = possibleIntent.inputValueData
545+
if (possibleIntent.intent === INTENT_NAMES.SIGN_IN) {
546+
assistResponse.signInIntent = true
547+
} else if (possibleIntent.intent === INTENT_NAMES.NEW_SURFACE) {
548+
const { capabilities, context, notificationTitle } = inputValueData
549+
assistResponse.newSurface = { capabilities, context, notificationTitle }
550+
}
534551
if (inputValueData) {
535552
const carouselSelect = inputValueData.carouselSelect
536553
const listSelect = inputValueData.listSelect

src/test/expected.ts

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,4 +860,82 @@ export const CONVERSATION_TABLE = {
860860
},
861861
},
862862
userStorage: '{\"data\":{}}',
863-
}
863+
}
864+
865+
export const CONVERSATION_SIGN_IN = {
866+
conversationToken: '[\"_actions_on_google\"]',
867+
expectUserResponse: true,
868+
expectedInputs: [
869+
{
870+
inputPrompt: {
871+
richInitialPrompt: {
872+
items: [
873+
{
874+
simpleResponse: {
875+
textToSpeech: 'You\'ll need to sign in',
876+
},
877+
},
878+
],
879+
},
880+
},
881+
possibleIntents: [
882+
{
883+
intent: 'actions.intent.SIGN_IN',
884+
inputValueData: {
885+
'@type': 'type.googleapis.com/google.actions.v2.SignInValueSpec',
886+
},
887+
},
888+
],
889+
},
890+
],
891+
responseMetadata: {
892+
status: {
893+
message: 'Success (200)',
894+
},
895+
queryMatchInfo: {
896+
queryMatched: true,
897+
intent: '4aca4776-5110-4f19-a76c-d96d7f4d5b18',
898+
},
899+
},
900+
userStorage: '{\data\:{}}',
901+
}
902+
903+
export const CONVERSATION_NEW_SURFACE = {
904+
conversationToken: '[\"_actions_on_google\"]',
905+
expectUserResponse: true,
906+
expectedInputs: [
907+
{
908+
inputPrompt: {
909+
richInitialPrompt: {
910+
items: [
911+
{
912+
simpleResponse: {
913+
textToSpeech: 'I\u0027m sorry. I\u0027m having trouble connecting to your account. Please try again later.',
914+
},
915+
},
916+
],
917+
},
918+
},
919+
possibleIntents: [
920+
{
921+
intent: 'actions.intent.NEW_SURFACE',
922+
inputValueData: {
923+
'@type': 'type.googleapis.com/google.actions.v2.NewSurfaceValueSpec',
924+
capabilities: ['actions.capability.SCREEN_OUTPUT'],
925+
context: 'There is more information available.',
926+
notificationTitle: 'Transferring to your phone',
927+
},
928+
},
929+
],
930+
},
931+
],
932+
responseMetadata: {
933+
status: {
934+
message: 'Success (200)',
935+
},
936+
queryMatchInfo: {
937+
queryMatched: true,
938+
intent: 'a457499e-b810-4aa7-b523-2ac5fa6b7e48',
939+
},
940+
},
941+
}

src/test/test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,35 @@ test.serial('verifies parsing a table', t => {
381381
mockResponse.restore()
382382
})
383383
})
384+
385+
test.serial('verifies parsing a sign in intent', t => {
386+
const action = new ActionsOnGoogleAva(testCredentials)
387+
const mockResponse = sinon.stub(action._client, 'assist')
388+
mockResponse.callsFake(() => {
389+
const conversation = getMockConversation(Sample.CONVERSATION_SIGN_IN)
390+
return conversation
391+
})
392+
393+
return action!.start('')
394+
.then((res: AssistResponse) => {
395+
t.is(res.signInIntent, true)
396+
mockResponse.restore()
397+
})
398+
})
399+
400+
test.serial('verifies parsing a new surface intent', t => {
401+
const action = new ActionsOnGoogleAva(testCredentials)
402+
const mockResponse = sinon.stub(action._client, 'assist')
403+
mockResponse.callsFake(() => {
404+
const conversation = getMockConversation(Sample.CONVERSATION_NEW_SURFACE)
405+
return conversation
406+
})
407+
408+
return action!.start('')
409+
.then((res: AssistResponse) => {
410+
t.deepEqual(res.newSurface!.capabilities, ['actions.capability.SCREEN_OUTPUT'])
411+
t.is(res.newSurface!.context, 'There is more information available.')
412+
t.is(res.newSurface!.notificationTitle, 'Transferring to your phone')
413+
mockResponse.restore()
414+
})
415+
})

0 commit comments

Comments
 (0)