Search code examples
reactjsbotframework

Hide Text Sent via Post Activity Event


I'm currently sending a text programmatically to my bot following the article on https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/d.post-activity-event

Everything is working fine but I want to hide the text being sent so that the user does not see it on the session. Is this possible to do?


Solution

  • Instead of initializing and using the useSendMessage hook, replace it with useSendPostBack. Using useSendPostBack will generate a postBack message activity which simply sends a value back to the bot without displaying it to the user. The value sent to the bot should be located in the value property of the associated activity.

    const sendPostBack = useSendPostBack();
    
    const handleHelpButtonClick = useCallback(() => sendPostBack('help'), [sendMessage]);
    

    A complete list of available hooks can be reviewed in the Web Chat repo doc, hooks.