Adding Middleware in Bot Framework Composer V2 - bot-framework-composer

I want to add a Middleware in a Bot Framework Composer project but I can't find any documentation on how to do it.
How would one go about adding a simple Middleware, let's say a Middleware that logs all the exchanged messages to console, in a bot created with Bot Framework Composer v2.1.1?

you have to mention the middleware component name in "configure -> settings.json" file.
ex:
"components": [
{
"name": "BotComposerMiddlewareComponent"
}
],
Note : BotComposerMiddlewareComponent is a middleware component
name.
find the sample here how to write the custom middleware for bot composer

Create a class file
Inherit this interface - Microsoft.Bot.Builder.IMiddleware
Implement OnTurnAsync Method like below code sample
You will have access to context, Activity and other stuffs you do in bot framework library implementations
I have wrote a detailed article on creating middleware for Bot Framework Composer here:
https://www.lkgforit.com/2022/10/implementing-middleware-in-bot.html

Related

AsyncAPI - How to distribute definition over different files

I am thinking of using AsyncAPI in my project for documenting the RabbitMQ messaging system.
What I need to do is, rather than creating a single yaml/json file for all the messages in the application, I want to create the AsyncAPI definition for each message in its own file, very much like its done in Swagger.
I am using Swagger 2.0, on a node express server for the REST API definitions. For the definition of the APIs, I write comments on each API with the #swagger decorator for Swagger to pick up the documentation. For example:
/**
* #swagger
* /user/register:
* post:
* description: Register a new user
...
...
*/
I also have a common definition in a routes.js file, where I define all the reusables.
Such definitions sit on the top of each API end point file. Swagger, collects all these documentations distributed over various files, and creates a single documentation for all the APIs in the application.
I was wondering if something similar can be done in AsyncAPI and if yes, how do I achieve that.
Would really appreciate your response on this.
Thanks,
Rachit
What I need to do is, rather than creating a single yaml/json file for all the messages in the application, I want to create the AsyncAPI definition for each message in its own file, very much like its done in Swagger.
Split definition of schema objects across several files is possible in AsyncAPI exactly in the same way like in OpenAPI
I am using Swagger 2.0, on a node express server for the REST API definitions. For the definition of the APIs, I write comments on each API with the #swagger decorator for Swagger to pick up the documentation. For example:
Up to now there is no code-first tool to generate AsyncAPI from the JS source code

Push Notifications Ionic

First of all, I'm developing a proyect in Ionic (front-end), Node.js + Express (backend) and MongoDB as DB and, I want to implement push notification in my app. I've read a lot about notification using firebase but I'm using MongoDB. I'm quite lost if anyone could help/guide me, I'd appreciate it.
You can use Firebase push or Firebase cloud messaging with your app without any issue. It is just one service of Firebase family. You don't need to use its real-time database with your app. You just need to integrate Firebase cloud messaging service only. i.e. you can keep Mongodb backend as it is now.
Article about Firebase Push and Ionic 4
If you don't want to use firebase and/or you want push notifications even if you are offline, there is this Cordova plugin you can use: cordova-plugin-local-notifications.
Quick instructions here. Not-so-quick instructions: read the documentations and issues in github.
Install like this:
ionic cordova plugin add cordova-plugin-local-notification
npm install #ionic-native/local-notifications
Then import and include the provider in app.module.ts (don't forget this step, usually not included in any manual):
import {LocalNotifications} from '#ionic-native/local-notifications/ngx';
...
providers: [ LocalNotifications ]
Then import and inject in your_page.page.ts:
import {LocalNotifications} from '#ionic-native/local-notifications/ngx';
...
constructor(private localNotifications: LocalNotifications) {}
And finally use it like this:
this.localNotifications.schedule({
title: 'My first notification',
text: 'Thats pretty easy...',
foreground: true
});
Test it thoroughly, the plugin is not bugfree, but works.
Hope this helps.

Generate openApi DTO's with NestJS without a Controller

I am writing a NestJS service that provides a REST API and it publishes some messages to NATS. We are using the NestJS support to generate OpenAPI docs, and from the OpenAPI docs we generate an SDK that we import into our clients. This all works great, but only the REST API of our code is in the SDK.
What we'd like to also do is to have NestJS include the DTO's for the content for the messages we publish to NATS. Then our SDK will also include interfaces for these DTO's, and then our clients can cast the message content to the correct interface (based on the message subject). This way, the publisher of an event defines the content of the event, and users of it don't have to replicate the interface, yet they get strongly-typed code.
I've tried adding the #Api decorators to the DTO, but it appears that unless the DTO is used in the definition of an #Controller, it is not included in the resultant openApi docs.
I was hoping for a way to decorate a "random" DTO in my code so it will then be included in the swagger docs, and in-turn included in a generated SDK. Is something like that possible?
you can also pass extraModels array as a part of SwaggerDocumentOptions
SwaggerModule.createDocument(app, config, {
extraModels: [.......]
});
https://github.com/nestjs/swagger/issues/241

How to set dynamic waterfall steps in Bot framework v4(.net core)?

I have bot in v3(.net framework) for multiple intent and every intent having different set of questions/steps. There I am using 'PromptOption. choice' for showing dynamic set of questions/steps and taking answer from 'resume' method. added code below.
PromptDialog.Choice( context: context, **resume: ResumeAfterPromptAnswer, options: promptData.Choices**, prompt: promptData.Text, retry: BotConstants.InvalidSelection, attempts: 2, promptStyle: PromptStyle.Auto );
Now I am trying to migrate my bot to v4 but I am not getting such prompt functionality in V4. just having option for waterfall steps but not able to add steps dynamicaly.
If you have any solution please post it.
Thanks in advance.
What you're attempting to do is entirely possible in v4. I recommend checking out these community extensions, since they offer some v3-ish functions in v4:
Bot Builder ChoiceFlow (I think this is what you're looking for)
Bot Builder v4 FormFlow
Alternatively, you could use the vanilla v4 SDK and Create advanced conversation flow using branches and loops. The Complex Dialog Sample is a pretty good example of how to do this.
All that being said, I don't 100% understand what you're asking. If this doesn't address your question, please provide an example conversation flow and I can adjust my answer.

How to build chatbot using botkit anywhere in nodejs application?

I am trying to build a chatbot using botkit anywhere and nodejs. I don't want to use any third-party messaging platform. I refer to this link https://github.com/howdyai/botkit#build-your-bot and try to setup chatbot in nodejs application:
First, add it to your project:
npm install --save botkit
Then, add Botkit to your application code:
var Botkit = require('botkit');
var controller = Botkit.anywhere(configuration);
controller.hears('hello','direct_message', function(bot, message) {
bot.reply(message,'Hello yourself!'); });
But they don't mention how to call and where to call this code in the existing application.
Before you start you need a NLU middle ware. Since you don't want to use 3rd party services, you can use RASA NLU and Botkit has easy integration too.
https://github.com/RasaHQ/rasa_nlu
Then You can the below easy to use Botkit-Anywhere-RASA library.
https://github.com/matteoredaelli/botkit-starter-web-rasa-nlu
1) Star the RASA NLU server
2) Clone the starter project (#2) and run using "node ."
For Botkit Web anywhere:
I followed following URL steps:
https://botkit.ai/getstarted.html
after these steps my folder structure is like below:
you can navigate to public->client.js and here you can find method.

Resources