MCPcopy
hub / github.com/claudiajs/claudia-bot-builder / addInput

Method addInput

lib/slack/format-dialog.js:42–100  ·  view source on GitHub ↗
(text, name, maxLength = 150, minLength = 0, optional = false, hint, subtype, value, placeholder)

Source from the content-addressed store, hash-verified

40 }
41
42 addInput(text, name, maxLength = 150, minLength = 0, optional = false, hint, subtype, value, placeholder) {
43 if (this.template.dialog.elements.length === 5)
44 throw new Error('You can not add more than 5 elements');
45
46 if (!text || !name)
47 throw new Error('Text and name are requeired for addInput method');
48
49 if (text.length > 24)
50 throw new Error('Text needs to be less or equal to 24 characters');
51
52 if (name.length > 300)
53 throw new Error('Name needs to be less or equal to 300 characters');
54
55 if (!(/^\+?(0|[1-9]\d*)$/.test(maxLength)) || maxLength > 150 || maxLength == 0)
56 throw new Error('Max length needs to be a valid number and less or equal to 150');
57
58 if (!(/^\+?(0|[1-9]\d*)$/.test(minLength)) || minLength >= 150)
59 throw new Error('Min length needs to be a valid number and less or equal to 150');
60
61 if (optional && typeof optional !== 'boolean')
62 throw new Error('Optional needs to be a boolean');
63
64 if (hint && (typeof hint !== 'string' || hint.length > 150))
65 throw new Error('Hint needs to be a valid string and less or equal to 150 characters');
66
67 if (subtype && (['text', 'email', 'number', 'tel', 'url'].indexOf(subtype) === -1 || typeof subtype !== 'string' || typeof subtype === 'boolean'))
68 throw new Error('The value of the subtype can be email, number, tel, url or text');
69
70 if (value && (typeof value !== 'string' || value.length > 150))
71 throw new Error('Value needs to be a valid string and less or equal to 150 characters');
72
73 if (placeholder && (typeof placeholder !== 'string' || placeholder.length > 150))
74 throw new Error('Placeholder needs to be a valid string and less or equal to 150 characters');
75
76 const inputElement = {
77 label: text,
78 name: name,
79 type: 'text',
80 max_length: maxLength,
81 min_length: minLength,
82 optional: optional
83 };
84
85 if (hint)
86 inputElement.hint = hint;
87
88 if (subtype)
89 inputElement.subtype = subtype;
90
91 if (value)
92 inputElement.value = value;
93
94 if (placeholder)
95 inputElement.placeholder = placeholder;
96
97 this.template.dialog.elements.push(inputElement);
98
99 return this;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected