npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

botbuilder-botbldr

v0.2.1

Published

Simple starters for botbuilder

Downloads

10

Readme

botbldr

Get up and running quickly with BotBuilder v4 with bot classes that add features to context and hide the messy plumbing.

You can use predefine classes for console and service bots, or bake your own.

This is an experimental project subject to change without notice. Use at your own risk. Not an officially supported Microsoft product.

How do I use it?

npm install --save botbuilder-botbldr

What does it look like?

Here's an echobot using the predefined ConsoleBot:

import { ConsoleBot } from 'botbuilder-botbldr';

const bot = new ConsoleBot();

bot.onTurn(async context => {
    context.conversationState.count = context.conversationState.count === undefined ? 0 : context.conversationState.count + 1;
    await context.sendActivity(`${context.conversationState.count}: You said "${context.request.text}"`);
});

Swap out ConsoleBot for ServiceBot to test your bot with Emulator then run it in the cloud in the Azure Bot Service.

Both use an extended version of BotContext called StateContext which adds .conversationState and .userState properties to context. Any changes you make to either of these are automatically persisted at the end of each turn. By default they use MemoryStorage as a state storage provider, but you can pass in any you like, e.g.

const bot = new ConsoleBot(new FileStorage("path_to_your_file"));

If you use TypeScript you can define types for these properties:

import { ConsoleBot } from 'botbuilder-botbldr';

interface MyConversationState {
    count: number;
}

interface MyUserState {
    name: string;
}

const bot = new ConsoleBot<MyConversationState, MyUserState>();

bot.onTurn(async context => {
    context.conversationState.count = context.conversationState.count === undefined ? 0 : context.conversationState.count + 1;
    await context.sendActivity(`${context.conversationState.count}: You said "${context.request.text}"`);
});

I don't like how you extended context (or I want to extend it more)

No problem, you can make your own extended context following the recipe used in /src/StateContext.ts. Then extend BaseBot following the recipe used in /src/StateBot.ts and /src/ConsoleBot.ts

Can I add my own middleware?

Sure, just add:

bot.use(new BestMiddlewareEver())

before your call to bot.onRequest

Can I use proactive messages?

Yes!

const calledBySomeEventSomewhere = async (activity: Activity) => {
    await bot.continueConversation(activity, async context => {
        await context.sendActivity(`Something happened!`);
    });
}