-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for interactive whatsapp messages (#332)
* Adding support for interactive whatsapp messages
- Loading branch information
1 parent
6397de7
commit 99464aa
Showing
6 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const Joi = require('joi'); | ||
|
||
// Schema for Row | ||
const rowSchema = Joi.object({ | ||
id: Joi.string().optional(), | ||
title: Joi.string().optional(), | ||
description: Joi.string().optional(), | ||
}); | ||
|
||
// Schema for Section | ||
const sectionSchema = Joi.object({ | ||
title: Joi.string().optional(), | ||
rows: Joi.array().items(rowSchema).optional(), | ||
}); | ||
|
||
// Schema for Buttons | ||
const buttonsSchema = Joi.object({ | ||
id: Joi.string().optional(), | ||
title: Joi.string().optional(), | ||
cta_url: Joi.string().optional(), | ||
}); | ||
|
||
// Schema for Action | ||
const actionSchema = Joi.object({ | ||
buttons: Joi.array().items(buttonsSchema).optional(), | ||
sections: Joi.array().items(sectionSchema).optional(), | ||
}); | ||
|
||
// Schema for Header | ||
const headerSchema = Joi.object({ | ||
type: Joi.string().optional(), | ||
text: Joi.string().optional(), | ||
media: Joi.string().optional(), | ||
}); | ||
|
||
// Schema for Body | ||
const bodySchema = Joi.object({ | ||
text: Joi.string().optional(), | ||
}); | ||
|
||
// Schema for Footer | ||
const footerSchema = Joi.object({ | ||
text: Joi.string().optional(), | ||
}); | ||
|
||
// Schema for Interactive | ||
const interactiveSchema = Joi.object({ | ||
type: Joi.string().optional(), | ||
header: headerSchema.optional(), | ||
body: bodySchema.optional(), | ||
footer: footerSchema.optional(), | ||
action: actionSchema.optional(), | ||
}); | ||
|
||
// Function to validate the data against the interactiveSchema | ||
function validateInteractive(data) { | ||
const { error, value } = interactiveSchema.validate(data, { allowUnknown: true }); | ||
return { error, value }; | ||
} | ||
|
||
module.exports = { | ||
validateInteractive, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters