Botframework Create Directline get token from server

时间秒杀一切 提交于 2021-02-11 13:28:53

问题


I saved the token from createdirectline first time it was initialized to the server. But whenever I get the token from the server and used it, it will not use that token instead it will create a new one.

  React.useEffect(() => {
    const temp = async () => {
      if (Object.entries(directline).length === 0) {
          if(await props.chatBotData!.tokenFromDb){
            setDirectline(createDirectLine({ token: props.chatBotData.tokenFromDb.toString() }));
          }else {
            setDirectline(createDirectLine({ token: DIRECTLINE_SECRET }));
          }
 
      }
    };
    temp();
  }, [directline,props.chatBotData]);
  const [directline, setDirectline]: any = useState({});


回答1:


You want to save the Direct Line secret server-side so it is inaccessible, not the token. The secret is used when making a call to /directline/tokens/generate or /directline/conversations in order to retrieve a token (and conversationId, if the latter endpoint). (Reference Connect a bot to Direct Line and Generate a Direct Line token.)

In short, this is the flow your site should follow:

  1. Web site with Web Chat loads.
  2. As Web Chat instantiates, an API call is made to your "token" server (i.e. https://.../gettoken.
  3. When the "token" server token API is called, it makes a call to /directline/tokens/generate passing the secret which then returns the token.
  4. The token is returned back to your calling web site which then passes it for use in createDirectLine().

It's important to note that tokens are only good for 30 mins, at the time of this writing, before they expire. If you are expecting a conversation to last longer than 30 mins, then you will need to perform a similar process to exchange the token for a refreshed token beforehand.

Hope of help!



来源:https://stackoverflow.com/questions/63823755/botframework-create-directline-get-token-from-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!