Feature request: to add additional parameters to the Chat message
- Dominant language
- TypeScript
- Stars
- 40
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
I am implementing BotMan web-widget plugin for https://www.userfrosting.com/ and building this as a sprinkle (UF's version of the plugin). [https://github.com/ssnukala/ufsprinkle-botsevak](https://github.com/ssnukala/ufsprinkle-botsevak)
I am able to initialize the BotMan web widget and get it to work, but when I send a message the POST is failing because UF checks for CSRF tokens in the post route. I am looking for a way to add additional fields like the CSRF tokens to be added to the POST along with the message and some of the other parameters that are being sent. [https://github.com/ssnukala/ufsprinkle-botsevak/issues/1](https://github.com/ssnukala/ufsprinkle-botsevak/issues/1).
I am looking at the following code on BotMan.
https://github.com/botman/web-widget/blob/master/src/chat/botman.ts#L17-L43
```
callAPI = (text: string, interactive = false, attachment: IAttachment = null, perMessageCallback: Function, callback: Function) => {
let data = new FormData();
const postData: { [index: string] : string|Blob } = {
driver: 'web',
userId: this.userId,
message: text,
attachment: attachment as Blob,
interactive: interactive ? '1' : '0'
};
Object.keys(postData).forEach(key => data.append(key, postData[key]));
```
I am thinking 2 potential options
Option 1. along with text add another array called [additionalParams] or something like that to append to the message. **additionalParams={}**
```
callAPI = (text: string, additionalParams={}, interactive = false, attachment: IAttachment = null, perMessageCallback: Function, callback: Function) => {
......
......
Object.keys(additionalParams).forEach(key => data.append(key, additionalParams[key]));
```
Option 2. provide a call back function to append to the POST data before the POST happens **beforePostCall: Function**
```
callAPI = (text: string, interactive = false, attachment: IAttachment = null, beforePostCall: Function, perMessageCallback: Function, callback: Function) => {
........
........
Object.keys(postData).forEach(key => data.append(key, postData[key]));
if (beforePostCall) {
data = beforePostCall(data);
}
axios.post(this.chatServer, data).then(response => {....
```
I am thinking Option 2 may be the way to go and will make this very flexible.
This will help dynamically add additional data to the POST message and open this up for additional use cases for a chat based application !
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.