How can I trigger events of ActiveHandler class in botframework v4 node sdk - botframework

I have gone through Bot v4 documentation and felt very surprised and happy by looking into Events of ActivityHandler class. But I am unable to trigger some of them in my bot through Facebook channel.
I have tried below code in my class which extends ActivityHandler class. Below mentioned events unable to trigger. In fact, I dont know how to trigger these events.
onEvent
onMembersRemoved
onReactionsAdded
onReactionsRemoved
onMessageReaction
onTokenResponseEvent
onUnrecognizedActivityType
Below is the code Snippet.
class DialogBot extends ActivityHandler {
constructor(conversationState, userState, dialog, logger,conversationReferences) {
super();
}
this.onEvent(async (context, next) => {
console.log('=========== from onEvent funcion from class=====');
await next();
});
this.onMembersRemoved(async (context, next) => {
console.log('----dialog bot.js ----onMembersRemoved---- ');
await next();
});
this.onMessageReaction(async (context, next) => {
console.log('----dialog bot.js ----onMessageReaction---- ');
await next();
});
this.onReactionsAdded(async (context, next) => {
console.log('----dialog bot.js ----onReactionsAdded---- ');
await next();
});
this.onReactionsRemoved(async (context, next) => {
console.log('----dialog bot.js ----onReactionsRemoved---- ');
await next();
});
this.onTokenResponseEvent(async (context, next) => {
console.log('----dialog bot.js ----onTokenResponseEvent---- ');
await next();
}) ;
this.onUnrecognizedActivityType(async (context, next) => {
console.log('----dialog bot.js ----onUnrecognizedActivityType---- ');
await next();
});
}
Please suggest the way to utilize these powerful events through facebook channel in bot framework v4 node sdk.
I look forward for your response. thanks.

Not all channels support all events.
onMembersRemoved -> Not supported by Facebook
onMessageReaction -> Not supported by Facebook
onReactionsAdded -> Not supported by Facebook
onReactionsRemoved -> No supported by Facebook
onTokenResponseEvent -> Which token?
This is a reference chart that show which channel supports which event activity.

Related

why can't I use async and await in the second middleware?

I found a demo in the koa-router official docs.
router.get(
'/users/:id',
(ctx, next) => {
//something
},
async ctx => {
//I can't use await here
}
);
But why can't I use async and await in the second middleware? I always got Not found response by default.

How to listen for Modal submission on Slack Bolt?

I've been looking through the docs for a day now, and still can't figure out this simple question: what is the #slack/bolt ^2.3.0 method that is used to listen for a Modal submission?
const slackbot = new App({ token, signingSecret });
slackbot.shortcut(
"open_modal",
async ({ ack, body, client, context, payload }) => {
await ack();
const result = await client.views.open({ ... });
}
);
slackbot.METHOD_HERE(ID_HERE,
async ({ ack }) => {
ack();
// handle modal submitted data here...
}
);
What values take the place of METHOD_HERE and ID_HERE in the code above?
I am able to open a modal without problem via the global shortcuts menu; but can't seem to figure out how to capture user's submission of the modal.
For example, this never captures any submissions:
slackbot.view("open_modal", async ({ ack }) => {
ack();
// do things here...
});
You need to use the callback_id used when you create the Modal view:
slackbot.shortcut(
"open_modal",
async ({ ack, body, client, context, payload }) => {
await ack();
const result = await client.views.open({
trigger_id: body.trigger_id,
view: {
type: "modal",
callback_id: "YOUR_CALLBACK_ID", // <= listen for this ID
title: {
type: "plain_text",
text: "Modal Title",
},
blocks: [ ... ],
},
});
}
);
Then, to listen to submissions on the above Modal, use this:
app.view('YOUR_CALLBACK_ID', optionalMiddleWareFunction, async ({ payload }) => {
const submittedValues = payload.view.state.values
// do stuff with submittedValues
});
callback_id is the ID that you defined when creating modal view. You can see an example here.
You can read the corresponding official documentation here.

How to stop video playing in background Nativescript -angular

Im using video in my project ,but video is playing in background ,When i move to another component.This problem occurs only in ios ,not in android
Html
<VideoPlayer
src="{{videoUrl}}"
height="300"></VideoPlayer>
angular
index:any
videoUrl :any
ngOnInit() {
this.router.paramMap.subscribe(
(response) =>{
this.index = response.get('id')
this.videoUrl=this.galleryService.getVideoById(this.index)
console.log(response)
}
)
}
This is my code .
Listen to navigatingFrom event on your current Page and call pause() method on the VideoPlayer.
HTML
<VideoPlayer #player
src="{{videoUrl}}"
height="300"></VideoPlayer>
TS
#ViewChild("player") player: ElementRef;
constructor(private page: Page) { }
ngOnInit() {
this.router.paramMap.subscribe(
(response) => {
this.index = response.get('id')
this.videoUrl=this.galleryService.getVideoById(this.index)
console.log(response)
});
this.page.on(Page.navigatingFromEvent, () => {
this.player.nativeElement.pause();
});
}
ngOnDestroy() {
this.page.off(Page.navigatingFromEvent);
}
You may also use Router Events on Angular, but you might have to filter the appropriate route.

replaceDialog() inside cancelAction

I am using a LUIS recognizer in my code to trigger dialogs. In one of my dialogs ('search') I would like to invoke the 'help' dialog when the user types 'cancel'. I was hoping to achieve this through the onSelectAction within the cancelAction. However I am getting an error:
(node:42184) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Dialog[BotBuilder:help] not found.
However I do have a 'help' dialog in my code. Is this happening because the 'help' is not in the dialog stack? Any pointers on how to debug this would be much appreciated.
var builder = require('botbuilder');
var restify = require('restify');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create connector and listen for messages
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector, function (session) {
session.replaceDialog('search');
});
bot.dialog('help', [
function (session, args, next) {
session.send('Help dialog');
}
]);
bot.dialog('search', [
function (session, args, next) {
builder.Prompts.text(session, 'What would you like to search?');
}
]).cancelAction('cancelAction', 'Ok, cancelling your search', {
matches: /^cancel$/,
onSelectAction: (session, args, next) => {
session.replaceDialog('help', args);
}
});
According the comment of replaceDialog:
Ends the current dialog and starts a new one its place. The parent dialog will not be resumed until the new dialog completes.
According the comment in source code of onSelectAction action:
/**
...
* It's important to note that this is not a waterfall and you should call `next()` if you
* would like the actions default behavior to run.
*/
onSelectAction?: (session: Session, args?: IActionRouteData, next?: Function) => void;
it seems that we need to call next() first, which can remove the botbuilder library, this action will change the library to *.
So, try following:
bot.dialog('search', [
function (session, args, next) {
builder.Prompts.text(session, 'What would you like to search?');
}
]).cancelAction('cancelAction', 'Ok, cancelling your search', {
matches: /^cancel$/,
onSelectAction: (session, args, next) => {
next();
session.replaceDialog('help', args);
}
});

POST request with parameters doesn't work with koa-router

I'm trying to build a simple REST API with Koa. For this, I am using koa-router. I have two problems:
Whenever I try to add parameters to my POST-Method in mainRouter.ts like ":id", Postman shows a "not found". My request: http://localhost:3000/posttest?id=200
I cannot get the parameters with "ctx.params". I also can't find anything about it on the koajs-page, but I do see examples like this everywhere?!
This is my app:
app.ts
import * as Koa from 'koa';
import * as mainRouter from './routing/mainRouter';
const app: Koa = new Koa();
app
.use(mainRouter.routes())
.use(mainRouter.allowedMethods());
app.listen(3000);
mainRouter.ts
import * as Router from 'koa-router';
const router: Router = new Router();
router
.get('/', async (ctx, next) => {
ctx.body = 'hello world';
});
router
.post('/posttest/:id', async (ctx, next) => {
ctx.body = ctx.params.id;
});
export = router;
If I change the POST-method to this, then I get "200":
router
.post('/posttest', async (ctx, next) => {
ctx.body = ctx.query.id;
});
If you're using a query string in your request like this:
http://localhost:3000/posttest?id=200
Then your route handler should be using ctx.query, not ctx.params:
router.post('/posttest', async (ctx, next) => {
console.log(ctx.query.id); // 200
});
You should only use ctx.params when you want to send requests like this:
http://localhost:3000/posttest/200
In which case you would write the route handler like so:
router.post('/posttest/:id', async (ctx, next) => {
console.log(ctx.params.id); // 200
});

Resources