Trigger Botpress bot response from RocketChat/Livechat when widget opened - rocket.chat

I’m using hlatki01/botpress-connector to connect RocketChat to my botpress bot. It’s working fine. However, visitors have to type something into the livechat widget to trigger an initial bot response. I’d prefer the bot agent to start the conversation as soon as the widget is opened. The botpress docs say the way to do this is by sending a botpress event from the page:
window.botpressWebChat.sendEvent({
type: "proactive-trigger",
channel: "web",
payload: {
text: "fake message",
},
})
... and catching the event in a botpress before_incoming_middleware hook.
However, I’m not embedding botpress on the page - I don’t have window.botpressWebChat. I’m a bit stuck - how can I trigger some sort of event when the livechat widget is opened, so that the botpress agent receives it and can greet the visitor?

Related

Slack App - Direct message NOT from slackbot

I have an app in Slack that sends direct messages to users. The messages always show up in the Slackbot channel and I would like to know if it is possible for the messages to show in the bot's own channel instead.
The app is made using bolt for NodeJS and here is my code:
app.client.chat.postMessage({
channel: userSlackId,
text: `TEXT HERE `,
token: process.env.SLACK_BOT_TOKEN,
icon_emoji: ":emoji",
username: "Incident Bot",
});
My scopes are:
chat:write
chat:write.customize
users:read
I believe you need the im:write scope as well to enable your app to directly message users.
You can update scopes from your app page -> OAuth & Permissions -> scroll down to scopes.

Microsoft Bot Famework - Webchat - event

Using botframework V4 - NodeJS - React Webchat V4
I am trying to send a message to bot, similar to a button click event in adaptive card. whenever a button is clicked in adaptive card i can see an event similar to below getting generated in the webchat
type: 'WEB_CHAT/SEND_POST_BACK',
payload: { value: {mytext: "myvalue"} }
Tried to send below dispatch message from the webchat on a custom button click, most of the time it is working and sometimes it wont send the message to bot. So i would like to know if this is the right approach or not. I can use WEB_CHAT/SEND_MESSAGE similar to below example
https://github.com/microsoft/BotFramework-WebChat/tree/master/samples/04.api/d.post-activity-event
but this is displaying the message on the chat window, i don't want to display the message that is sent to bot in my chat window.
this.store.dispatch({
type: 'WEB_CHAT/SEND_POST_BACK',
payload: { value: {buttonClick: "mytext", scanText: myvalue} }
});

Is there a way to send the data from the web form to the microsoft botframework web client without opening the web client?

We have a Angular application with .Net core.
When the users type on the input from their web page form field, it will need to be passed to the Microsoft BOT framework.
The response message from the BOT service will need to be displayed back to the Bot Chat client.
Users will review the above response and have the ability to send the received data from Bot Client back to the web page form fields.
I have read about the Web chat client and the Direct Line bot.
I can use Web chat client but I am not sure how to pass the input from my web form to it as I don't want the user to open the web chat to enter the same data again.
If I use the Direct Line Bot, I have control on passing the form input to the Bot service. In this case, I will need to spend time to build the Web client to display and process the messages.
You can do this by utilizing the DirectLine connection instance that you give to the WebChat control when you create it. The connection instance will enable you to both send events into the bot as well as watch for events coming out of the connection. At the same time, since you're sharing the connection with the chat control, the chat control can perform its typical duties of sending and receiving/displaying message contents.
For example, when the user clicks on the submit button on your form, you would utilize the connection object to send an event that contains your payload like so:
Setup DirectLine connection
Create the DirectLine connection at start up and assign it to your WebChat control, but also hold onto the connection object in a variable you can utilize in other places such as the form button click.
const directLineToken = await getDirectLineToken();
const directLineConnection = createDirectLine({ directLineToken });
Form button click logic
In the form button click logic you can now send an event activity that represents your proprietary backchannel event to the bot containing the form details as the payload:
const fancyFormEventPayload = {
fieldA: fieldAFormElement.value,
fieldB: fieldBFormElement.value,
// etc
};
// NOTE: this returns an observable that you can wait on
// to watch for errors or know when it has completed. I'm
// just using fire and forget here for now
directLineConnection.postActivity({
type: "event",
name: "myFancyFormSubmitted",
value: fancyFormEventPayload,
});
Listening for events coming back
Now the bot might respond with some message activities which the WebChat would then display, but it could also send back an event activity that contains the updated form payload which you could watch for and grab to populate the form with the updated values if they say "yes" for that.
// The connection exposes the stream of incoming activities via Rx, so
// we create filtered subscription that will process only the activity
// we're interested in and update the form fields in response to that
directLineConnection.activity$
.filter(activity => activity.type === 'event' && activity.name === 'myFancyFormUpdate')
.subscribe(activity =>
{
const myFancyFormPayload = activity.value;
fieldAFormElement.value = myFancyFormPayload.fieldA;
fieldBFormElement.value = myFancyFormPayload.fieldB;
// etc
});

Does the Microsoft/BotFramework-WebChat have a Sneak Peek feature?

I am using a customised Microsoft Bot Framework WebChat Client. My bot has the capability to hand to a live chat service with an Agent, when it is unable to provide a solution to the user.
I have the requirement to allow the agents to have a "sneak peek" at what is currently being typed into the Webchat Client.
I have enabled the sendTyping feature in chat.html (i.e. sendTyping: true):
BotChat.App({
bot: bot,
botConnection: botConnection,
locale: 'agent',
resize: 'window',
sendTyping: true, // defaults to false. set to true to send 'typing' activities to bot (and other users) when user is typing
user: user
}, document.getElementById('BotChatGoesHere')
);
When inspecting the outbound typing message, the typing event is sent (debounced about every three seconds or so), however it contains no text. I suspect this is not a feature, however I would kindly ask the community if anyone has done this previously and if so how to implement?
Thanks in advance.
This isn't supported indeed, the 'SendTyping' event doesn't contain any metadata about the state of the inputfield.
You could leverage the backchannel to send custom events. In your custom WebChat implementation, you can send a custom event on every keystroke or every x seconds. However, if you link to another agent service, maybe it can be smarter to call their / a custom API directly.
Make sure you have the consent of the user, since I don't think you can just send all keystrokes without consent.

response to conversationUpdate on Skype for Business

I intend to send a greeting message from the bot on Skype for Business when the user initially opens the chat window. To achieve this I'm trying to respond to the conversationUpdate event from the bot. When I respond to the conversationUpdate event, i receive the following error that conversation does not exits
{"Error":{"Code":"ServiceError","Message":"Conversation does not
exist"}}
But when the same user sends a message, I receive the message with the same conversationId and am able to respond back without any issues.
I'm able to do this without any issues on the web chat but not on SfB. I looked at some issues on Microsoft's GitHub repository for the bot, which suggested that the question may be best answered on SO.
Updates
I was earlier on SfB 2013. I've upgraded to SfB 2016 and the bot responds to the conversationUpdate event it receives once the user sends his first message. Usually on a web chat, the response to the first conversationUpdate is sent as soon as the user opens the window and a second response is sent once the user sends his first message. In the case of SfB, the response to second conversationUpdate is working but not for the first conversationUpdate.
Web Chat
Skype for Business
As explained above, the response to first conversationUpdate will result in the
Conversation does not exist
error. The response to the second conversationUpdate when user sends his first message works.
So now how do we make the welcome message work for the first conversationUpdate and disable it for the second conversationUpdate update ?
I am not sure, why converstaionUpdate event didn't triggered. But as mentioned in BotFramework docs, not every channels supports that event. You can add a first run dialog instead and check if that works. Adding a sample from the docs page:
// Add first run dialog
bot.dialog('firstRun', function (session) {
session.userData.firstRun = true;
session.send("Hello...").endDialog();
}).triggerAction({
onFindAction: function (context, callback) {
// Only trigger if we've never seen user before
if (!context.userData.firstRun) {
// Return a score of 1.1 to ensure the first run dialog wins
callback(null, 1.1);
} else {
callback(null, 0.0);
}
}
});

Resources