Giter Site home page Giter Site logo

newbienewbie / indirectline Goto Github PK

View Code? Open in Web Editor NEW
20.0 5.0 10.0 1.65 MB

Your own DirectLine that runs without Azure

License: MIT License

C# 95.65% HTML 2.70% Dockerfile 1.64%
botbuilder bot-framework directline azure-bot-service weixin-bot webchat

indirectline's Introduction

InDirectLine@GitHub

InDirectLine

Azure rocks. But sometime we need Host our own DirectLine & Bot Framework without Azure. For example, test webchat with no internet. :)

WebChat-demo WeChat MP demo

How it works

Actually, the DirectLine is a bridge that connects your bot and your client. This project (InDirectLine) is a custom implementation of my own written using ASP.NET Core.

For more details, see Direct Line API 3.0

Features & ToDo

  • REST API for normal messages
  • WebSocket support
  • Attachment support
    • Basic support : allow uploading
    • allow download
  • Security
    • Token Generate & Refresh API
    • Any user can only access his own conversation data
  • Persistene Layer & InMemory storage & clean up resources automatically
  • Wechat MP support
  • Unit Tests

How to Use

Typically, InDirectLine will be used as an standlone server (Itminus.InDirectLine.Web). In this way, the InDirectLine & your Bot are two different processes. You could create your Bot in C#/Node.js/Python/Java languages as you like.

WebChat

In order to use Directline with WebChat, we need create a directLine instance by WebChat.createDirectLine() firstly:

<div id="webchat" role="main"></div>
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat-minimal.js"></script>
<script>
        var userId ="User-"+ parseInt(Math.random()* 1000000);
        var userName = userId;
        fetch('/v3/directline/tokens/generate', { 
            method: 'POST',
            headers:{
                "Content-Type":"application/json",
            },
            body: JSON.stringify({ userId: userId, password: ""}),
        })
        .then(res => res.json())
        .then(res => {
            var directLine = window.WebChat.createDirectLine({
                domain: "/v3/directline",
                token: res.token,
            });
            window.WebChat.renderWebChat({
                directLine: directLine,
                userID: userId,
                username: userName,
                locale: 'en-US',
            }, document.getElementById('webchat'));
        });
</script>

Note the domain has no trailing slash /.

The WebChat will use WebSocket by default. If you want a REST way, set the webSocket=false:

    var directLine = window.WebChat.createDirectLine({
        domain: "http://localhost:3000/v3/directline",
        token: 'YOUR_DIRECT_LINE_TOKEN',
        webSocket:false, 
    });

WeChat

See Itminus.InDirectLine.IntegrationBotSample.

InDirectLine Configuration

The InDirectLine reads the appsettings.json file by default, which means it should listen on http://localhost:3000 and assumes that the http://127.0.0.1:5000/api/messages is the bot message endpoint.

You could create a appsettings.Development.json or a appsettings.Production.json and configure the options as you like. To use other ports, see Itminus.InDirectLine.IntegrationBotSample.

Also you could pass the settings by command line arguments or by environment variables.

For more details, see Microsoft Docs.

indirectline's People

Contributors

mrdave1999 avatar newbienewbie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

indirectline's Issues

样式丢失

哥们 我看你的网页例子样式咋丢失了啊,我测试运行也是这个情况。望指教

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.