Completed
Push — master ( 4fcad4...efcce7 )
by Muhammad Dyas
19s queued 16s
created

src/helpers/response.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 46
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 19
mnd 0
bc 0
fnc 2
dl 0
loc 46
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A response.ts ➔ createDialogActionResponse 0 19 1
A response.ts ➔ createStatusActionResponse 0 19 1
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