Pass Custom Parameters from webchat control to bot framework

后端 未结 2 831
闹比i
闹比i 2021-01-24 20:04

So, I\'m currently using this:



  
    
相关标签:
2条回答
  • 2021-01-24 20:59

    From Cilent Side

    var d1 = window.WebChat.createDirectLine({ token })
    window.WebChat.renderWebChat({
            directLine: Object.assign({}, d1, {
         postActivity: activity => {
         var newActivity = Object.assign({}, activity, { channelData: { "param1": "test" } });
         return d1.postActivity(newActivity);
        }
      }),
                styleSet,
                botAvatarInitials: 'CAB',
                userAvatarInitials: 'You'
    
    }, document.getElementById('webchat'));
    })();
    

    from BOt Framework

    var channelObj = turnContext.Activity.ChannelData.ToString();
    var channeldata = Newtonsoft.Json.Linq.JObject.Parse(channelObj);
    var customdata = channeldata["param1"].ToString();
    
    0 讨论(0)
  • 2021-01-24 21:06

    The other answer provided is helpful but it overwrites channelData. For others finding this answer and just wanting to send custom parameters, this will be helpful:

    const originalDirectline = props.webchat.createDirectLine({
        token,
    })
    
    const directLine = Object.assign({}, originalDirectline, {
        postActivity: (activity: any) => {
            const newActivity = Object.assign({}, activity)
            newActivity.customParam = "custom value"
            return originalDirectline.postActivity(newActivity)
        }
    })
    
    0 讨论(0)
提交回复
热议问题