馃毃 The issue tracker is not for implementation questions 馃毃
[Question]
I guess this is a couple questions about activating a chat bot once the client enters the endpoint of the chatbot? Upon using the renderChatBot webchat api and creating a directLine instance a directLine.postActivity() method can be fired off to initiate the bot so if there is a welcome card it will trigger and introduce itself to the end-user.
Is posting an event like this best practice? Is there a more official, alternative and or better way of doing this? I ask because in the example below it is an event that is fired off but what about a message and text event. Does username and name even matter for anything useful in terms of the chatbot?
Ultimately, to fire off the bot is using the postActivity the only way of really achieving this?
directLine
.postActivity({
from: { id: this.userId, name: "USER_NAME" },
name: "requestWelcomeDialog",
type: "event",
value: "token"
})
.subscribe(
id => console.log(`Posted activity, assigned ID ${id}`),
error => console.log(`Error posting activity ${error}`)
);
In the shoes of DirectLineJS, yes, this is the correct way to do it. You need to be careful if the connection is not established, this postActivity may fail. You should wait until connectionStatus$ turns to 2 (online). Also note connection may get interrupted from time to time.
In Web Chat, the code is still working fine. If you are looking for sending a message (instead of event), the better solution would be using Redux action named sendMessage/sendFile/sendEvent. Few reasons for Web Chat's version:
Activity, Web Chat will try to fill them out for you as much as it could, e.g. from. And we are planning to fill the localTimestamp field in #193 tooBut it still perfectly fine to use DLJS.postActivity().
@compulim when I am referring to directLine I mean the directLine from the WebChat.createDirectLine(). So specifically I am talking about activating the webchat bot when the user enters the application...
here is a code sample:
const directLine: DirectLine = window.WebChat.createDirectLine({
secret: token,
webSocket: this.webSocket
});
@xtianus79 Somewhat related to https://github.com/microsoft/BotFramework-DirectLineJS/issues/184#issuecomment-505162246. Might be worth taking a look.
@xtianus79 Yap, even createDirectLine is called, you will need to wait a few moment until it is connected. @tdurnford comment should be good starting point to read how it works. 馃槃
@tdurnford Yes, exactly what I was wondering lol you always have those exact answers. @compulim just to ask there's no real reason in a production bot to go beyond that initial post activity for a back-channel event starter? Wanted to confirm that.
@xtianus79 if you鈥檙e trying to send a Welcome Message in Web Chat, you might also want to look at https://github.com/microsoft/BotFramework-WebChat/issues/2120#issuecomment-516056614. There have been some recent changes to the Direct Line Connector Service that might simplify things for you.
Most helpful comment
@xtianus79 Somewhat related to https://github.com/microsoft/BotFramework-DirectLineJS/issues/184#issuecomment-505162246. Might be worth taking a look.