Skip to content

Commit

Permalink
feat(web): added config var for message length (resolve #1298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmytro Panontko committed Jan 18, 2019
1 parent 3bd0c43 commit a442b43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions modules/channel-web/src/backend/api.ts
Expand Up @@ -19,7 +19,7 @@ export default async (bp: typeof sdk, db: Database) => {
files: 1,
fileSize: 5242880 // 5MB
},
filename: function(req, file, cb) {
filename: function (req, file, cb) {
const userId = _.get(req, 'params.userId') || 'anonymous'
const ext = path.extname(file.originalname)

Expand Down Expand Up @@ -59,7 +59,7 @@ export default async (bp: typeof sdk, db: Database) => {
contentType: multers3.AUTO_CONTENT_TYPE,
cacheControl: 'max-age=31536000', // one year caching
acl: 'public-read',
key: function(req, file, cb) {
key: function (req, file, cb) {
const userId = _.get(req, 'params.userId') || 'anonymous'
const ext = path.extname(file.originalname)

Expand Down Expand Up @@ -187,7 +187,9 @@ export default async (bp: typeof sdk, db: Database) => {
}

async function sendNewMessage(botId: string, userId: string, conversationId, payload) {
if (!payload.text || !_.isString(payload.text) || payload.text.length > 360) {
const config = await bp.config.getModuleConfigForBot('channel-web', botId)

if (!payload.text || !_.isString(payload.text) || payload.text.length > config.maxMessageLength) {
throw new Error('Text must be a valid string of less than 360 chars')
}

Expand Down
4 changes: 4 additions & 0 deletions modules/channel-web/src/config.ts
Expand Up @@ -27,4 +27,8 @@ export interface Config {
* @default 6 hours
*/
recentConversationLifetime?: string
/**
* @default 360
*/
maxMessageLength?: number
}

0 comments on commit a442b43

Please sign in to comment.