Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: to add additional parameters to the Chat message #11

Open
ssnukala opened this issue Apr 15, 2018 · 3 comments
Open

Feature request: to add additional parameters to the Chat message #11

ssnukala opened this issue Apr 15, 2018 · 3 comments

Comments

@ssnukala
Copy link

ssnukala commented Apr 15, 2018

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

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. ssnukala/ufsprinkle-botsevak#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 !

@ssnukala
Copy link
Author

Please let me know if you had a chance to look into this.

@alexandrubau
Copy link

I've had the same problem: needed to send extra parameters to server. So I've created a pull request.
Check it out.

@EranGrin
Copy link

I created a new package that solves this and several other issues
https://www.npmjs.com/package/botman-extended-web-widget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants