Code Monkey home page Code Monkey logo

coco-microsoft-bot-framework's Introduction

A Toolkit to work with components in Microsoft Bot Framework

Installation (We recommend using a virtualenv):

pip install coco-microsoft-bot-framework 

Setup:

Setting Conversation State

in app.py, include the lines below.

from coco_microsoft_bot_framework import CoCoActivityHandler
from botbuilder.core import (
    BotFrameworkAdapterSettings,
    TurnContext,
    BotFrameworkAdapter,
    UserState,
    MemoryStorage,
    ConversationState,
)

MEMORY = MemoryStorage()
CONVERSATION_STATE = ConversationState(MEMORY)
# Create the Bot
BOT = MyBot(CONVERSATION_STATE)

Setting Activity Handler

in bot.py

Import CoCo custom Activity Handler, then use it to create your bot. At the on_message_activity method add the three lines as below, in order to manage CoCo context during the conversation.

from coco_microsoft_bot_framework import CoCoActivityHandler

class MyBot(CoCoActivityHandler):

    async def on_message_activity(self, turn_context: TurnContext):
        if self.is_component_active():
            await self.call_active_component(turn_context)
            return

Activate CoCo Component

Activate CoCo register component, which ID is: "register_vp3".

class MyBot(CoCoActivityHandler):

    async def on_message_activity(self, turn_context: TurnContext):
        if self.is_component_active():
            await self.call_active_component(turn_context)
            return
    
        if intent == "register":
            await self.activate_component(turn_context, "register_vp3")
        else:
            await turn_context.send_activity("I don't understand.")

coco-microsoft-bot-framework's People

Contributors

victorcoco avatar

Watchers

James Cloos avatar Chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.