Total Complexity | 2 |
Complexity/F | 1 |
Lines of Code | 46 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1'; |
||
2 | |||
3 | /** |
||
4 | * Creates an action response. |
||
5 | * Action Response is parameter that a Chat app can use to configure how its |
||
6 | * response is posted. |
||
7 | * ref: https://developers.google.com/chat/api/reference/rest/v1/spaces.messages#actionresponse |
||
8 | * |
||
9 | * @param {string} message - Number of votes for this option |
||
10 | * @param {string} status - Status of |
||
11 | * @returns {object} - ActionResponse |
||
12 | */ |
||
13 | export function createStatusActionResponse(message: string, status = 'OK') { |
||
14 | return { |
||
15 | actionResponse: { |
||
16 | type: 'DIALOG', |
||
17 | dialogAction: { |
||
18 | actionStatus: { |
||
19 | statusCode: status, |
||
20 | userFacingMessage: message, |
||
21 | }, |
||
22 | }, |
||
23 | }, |
||
24 | }; |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Creates an action response with specific type |
||
29 | * ref: https://developers.google.com/chat/api/reference/rest/v1/spaces.messages#responsetype |
||
30 | * @param {object} message - Card message either text or cardsV2 |
||
31 | * @returns {object} - ActionResponse |
||
32 | */ |
||
33 | export function createDialogActionResponse(message: object) { |
||
34 | const responseBody: chatV1.Schema$Message = { |
||
35 | actionResponse: { |
||
36 | type: 'DIALOG', |
||
37 | dialogAction: { |
||
38 | dialog: { |
||
39 | body: message, |
||
40 | }, |
||
41 | }, |
||
42 | }, |
||
43 | }; |
||
44 | return responseBody; |
||
45 | } |
||
46 |