-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
How to make sendMessage() accessible to the window object? #832
Comments
I'm not clear exactly what you're trying to achieve here. Can you provide more detail than "send message from JS to the server"? |
When a users click a custom button of my bot, I use directLine to post an activity of message type to the server:
This is basically the same as user typing in the built-in text input and click the send button. The only problem with my method is there's no chat bubble inserted to the right of the chat window telling user which button they clicked. Using built-in text input: Using custom button and directLine: |
Not a clean method but you can use this. //Fill the input field : Using a Hack. This might break after the next React update
//Source: https://github.com/facebook/react/issues/11488
var input = document.getElementsByClassName("wc-shellinput")[0];
var lastValue = input.value;
input.value = **YOUR TEXT**;
var event = new CustomEvent('input', { bubbles: true });
// hack React15
event.simulated = true;
// hack React16
var tracker = input._valueTracker;
if (tracker) {
tracker.setValue(lastValue);
}
input.dispatchEvent(event);
$(".wc-send:first").click(); |
Currently, we do not expose any APIs. But it's something in our plan. |
We now expose API on Web Chat v4. You can access the API via two ways:
|
I want to send message from JS to the server. While I can do it through directLine, there's no chat bubble inserted to .wc-message-groups as it seems that is controlled by React.
Some people in this thread suggests making sendMessage() public but with my limited knowledge in React I am having difficulty making it work.
Any general direction on how to achieve this?
The text was updated successfully, but these errors were encountered: