-
Notifications
You must be signed in to change notification settings - Fork 5
/
contentfulEntry.js
129 lines (127 loc) · 4.34 KB
/
contentfulEntry.js
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
'use strict';
const templateFieldTypes = {
text: 'text',
transition: 'transition',
};
/**
* This maps the fields in our Contentful types into broadcast, topic, and defaultTopicTriggers.
*
* Content types with either a templates or postType property set are returned as topics.
* If the type contains a templates array, each array item should correspond to a single value text
* field defined on the content type, which is used as a bot reply template in the topic.
* If the type contains a postType string property instead, its an older content type and its
* templates are configured via config/lib/helpers/topic. Ideally we should consolidate, but it'd
* take a bit of refactoring as the topic helper config contains default values for certain text
* fields to use if the field values are blank.
*
* A broadcastable content type currently requires a text field named "text" and attachments field
* named "attachments" to define content for the outbound broadcast. If a topic reference field
* exists, it will include the topic in the outbound message, indicating that the conversation topic
* should be updated upon receiving the broadcast (otherwise, the broadcast itself can be used as a
* topic if it has templates -- e.g. askYesNo)
*/
module.exports = {
contentTypes: {
askSubscriptionStatus: {
type: 'askSubscriptionStatus',
broadcastable: true,
},
askVotingPlanStatus: {
type: 'askVotingPlanStatus',
broadcastable: true,
templates: {
// These template names correspond to the macros that get executed if user matches a trigger
// within the ask_voting_plan_status topic in Gambit Conversations.
// @see https://github.com/DoSomething/gambit-conversations/blob/master/brain/topics/askVotingPlanStatus.rive
votingPlanStatusCantVote: {
fieldName: 'cantVoteTransition',
fieldType: templateFieldTypes.transition,
name: 'votingPlanStatusCantVote',
},
votingPlanStatusNotVoting: {
fieldName: 'notVotingTransition',
fieldType: templateFieldTypes.transition,
name: 'votingPlanStatusNotVoting',
},
votingPlanStatusVoted: {
fieldName: 'votedTransition',
fieldType: templateFieldTypes.transition,
name: 'votingPlanStatusVoted',
},
},
},
askYesNo: {
type: 'askYesNo',
broadcastable: true,
templates: {
invalidAskYesNoResponse: {
fieldName: 'invalidAskYesNoResponse',
fieldType: templateFieldTypes.text,
name: 'invalidAskYesNoResponse',
},
saidYes: {
fieldName: 'yesTransition',
fieldType: templateFieldTypes.transition,
name: 'saidYes',
},
saidNo: {
fieldName: 'noTransition',
fieldType: templateFieldTypes.transition,
name: 'saidNo',
},
},
},
autoReply: {
type: 'autoReply',
templates: {
autoReply: {
fieldName: 'autoReply',
fieldType: templateFieldTypes.text,
name: 'autoReply',
},
},
},
autoReplyBroadcast: {
type: 'autoReplyBroadcast',
broadcastable: true,
},
defaultTopicTrigger: {
type: 'defaultTopicTrigger',
},
message: {
type: 'message',
},
photoPostBroadcast: {
type: 'photoPostBroadcast',
broadcastable: true,
},
photoPostConfig: {
type: 'photoPostConfig',
// TODO: Refactor photoPostConfig in config/lib/helpers/topic here to DRY.
postType: 'photo',
},
textPostBroadcast: {
type: 'textPostBroadcast',
broadcastable: true,
},
textPostConfig: {
type: 'textPostConfig',
// TODO: Move textPostConfig in config/lib/helpers/topic here to DRY.
postType: 'text',
},
// Legacy types:
// Ideally we'd backfill all legacy entries as their new types, but we likely can't change the
// the type of a Contentful entry without changing its id (if that's the case - we'd need to
// bulk update all documents in the Conversations messages DB)
// This externalPostConfig type will deprecated by an autoReply:
externalPostConfig: {
type: 'externalPostConfig',
postType: 'external',
},
legacyBroadcast: {
type: 'broadcast',
broadcastable: true,
},
},
templateFieldTypes,
};