2.5.0 • Published 5 years ago

botbuilder-linebot-connector v2.5.0

Weekly downloads
167
License
-
Repository
github
Last release
5 years ago

botbuilder-linebot-connector

Microsoft Bot Framework V3 connector for Line office account

npm version dependencies Status

Features

  • ready for Microsoft Bot Framework V3
  • no need a registered bot on dev.botframework.com, but require a certified line developer account, go to apply trial account
  • depend on line and line-message-api packages
  • support receiving and sending almost any line message types
  • for express framework
  • serverless framework support - connector.serverlessWebhock(event)

LINE Messaging API for Node.js

About LINE Messaging API

Please refer to the official API documents for details.

Installation

npm install --save botbuilder-linebot-connector

Donate; Buy me a Beer

If you want to thank me, or promote your Issue.

Donate

Sorry, but I have work and support for packages requires some time after work. I will be glad of your support and PR's.

Document

Code Sample

javaScript

var builder = require("botbuilder")
var LineConnector = require("botbuilder-linebot-connector");

var express = require('express');
var server = express();

server.listen(process.env.port || process.env.PORT || 3980, function () {
    console.log("listening to");
});


var connector = new LineConnector.LineConnector({
    hasPushApi: false, //you have to pay for push api >.,<
    autoGetUserProfile:true, //default is false
    // your line
    channelId: process.env.channelId || "",
    channelSecret: process.env.channelSecret || "",
    channelAccessToken: process.env.channelAccessToken || ""
});

server.post('/line', connector.listen());

var bot = new builder.UniversalBot(connector)

var push = new builder.Message()
    .address(<any>a)
    .addAttachment(new ImageMap(<any>a,
        "test",
        "https://www.profolio.com/sites/default/files/styles/1920x1040/public/field/image/Bikini_Girls_adx.jpg?itok=uciEvomy",
        {
            "width": 1040,
            "height": 1040
        },
        []
    ))
bot.send(push);

bot.dialog("/", s => {
            try{
                let u = await connector.getUserProfile(s.message.from.id)
                console.log("u" + u)
                if (u === undefined) {
                    s.send("who said:" + s.message.text)
                } else {
                    s.send("hello " + u.displayName)
                }
            }catch(e){
                s.send("can`t get user profile!")
            }
            //image map
            
        s.send(new builder.Message(s).addAttachment(new ImageMap(s,
            "test",
            "https://www.profolio.com/sites/default/files/styles/1920x1040/public/field/image/Bikini_Girls_adx.jpg?itok=uciEvomy",
            {
                "width": 1040,
                "height": 1040
            },
            [
                {
                    "type": "uri",
                    "linkUri": "https://google.com/",
                    "area": {
                        "x": 0,
                        "y": 0,
                        "width": 333,
                        "height": 1040
                    }
                },
                {
                    "type": "message",
                    "label": "good",
                    "text": "hot",
                    "area": {
                        "x": 333,
                        "y": 0,
                        "width": 333,
                        "height": 1040
                    }
                },
            ]


        )));

    s.send(new builder.Message(s)
        /* Sticker  */
        .addAttachment(
            new LineConnector.Sticker(s, 1, 1)
        )
        /* Location  */
        .addAttachment(
            new LineConnector.Location(s, "my test", "中和", 35.65910807942215, 139.70372892916203)
        )
        /* Audio file */
        .addAttachment(
            new builder.AudioCard(s).media([{
                url: "https://xxx", //file place must be https
                profile: "music"
            }])
            /* Image file */
        ).addAttachment(
            new builder.MediaCard(s).image(builder.CardImage.create(s, 'https://imagelab.nownews.com/?w=1080&q=85&src=http://s.nownews.com/5d/6b/5d6b74b674e643f522ed68ef83053a1f.JPG'))
            /* Video file */
        ).addAttachment(
            new builder.MediaCard(s).media('https://imagelab.nownews.com/?w=1080&q=85&src=http://s.nownews.com/5d/6b/5d6b74b674e643f522ed68ef83053a1f.JPG').image(builder.CardImage.create(s, 'https://imagelab.nownews.com/?w=1080&q=85&src=http://s.nownews.com/5d/6b/5d6b74b674e643f522ed68ef83053a1f.JPG'))
        )
    );


    /* Dialog */
    s.send(new builder.Message(s)
        .addAttachment(
            new builder.HeroCard(s)

            .title("Classic White T-Shirt")
            .subtitle("100% Soft and Luxurious Cotton")
            .text("Price is $25 and carried in sizes (S, M, L, and XL)")
            .images([builder.CardImage.create(s, 'https://imagelab.nownews.com/?w=1080&q=85&src=http://s.nownews.com/11/b9/11b93df1ec7012f4d772c8bb0ac74e10.png')])

            .buttons([
                //left text message
                builder.CardAction.imBack(s, "buy classic gray t-shirt", "Buy"),
                //set timer
                new builder.CardAction().type("datatimepicker").title("time"),
                //postback
                builder.CardAction.postBack(s, "action=buy&itemid=111", "send data"),
                //open irl
                builder.CardAction.openUrl(s, "https://1797.tw", "1797")

            ])
        )
    )
        /* Carosuel */
          
        var msg = new builder.Message(s);
        msg.attachmentLayout(builder.AttachmentLayout.carousel)
        msg.attachments([

            new builder.HeroCard(s)
                .title("Classic White T-Shirt")
                .subtitle("100% Soft and Luxurious Cotton")
                .text("Price is $25 and carried in sizes (S, M, L, and XL)")
                .images([builder.CardImage.create(s, 'https://imagelab.nownews.com/?w=1080&q=85&src=http://s.nownews.com/11/b9/11b93df1ec7012f4d772c8bb0ac74e10.png')])
                .buttons([
                    builder.CardAction.openUrl(s, "https://1797.tw", "1797"),
                    new builder.CardAction().type("datatimepicker").title("time"),
                    builder.CardAction.postBack(s, "action=buy&itemid=111", "send data"),
                ]),
            new builder.HeroCard(s)
                .title("Classic Gray T-Shirt")
                .subtitle("100% Soft and Luxurious Cotton")
                .text("Price is $25 and carried in sizes (S, M, L, and XL)")
                .images([builder.CardImage.create(s, 'https://imagelab.nownews.com/?w=1080&q=85&src=http://s.nownews.com/5d/6b/5d6b74b674e643f522ed68ef83053a1f.JPG')])
                .buttons([
                    new builder.CardAction().type("datatimepicker").title("time"),
                    builder.CardAction.imBack(s, "buy classic gray t-shirt", "Buy"),
                    builder.CardAction.postBack(s, "action=buy&itemid=111", "send data"),
                ])
        ]);
        s.send(msg)


})


bot.dialog('leave'
    , s => {
        s.send("byebye");
        //only work in group or room
        connector.leave();

        s.endDialog()

    }
).triggerAction({
    matches: /^leave$/i
});

bot.on('conversationUpdate', function (message) {
    // detect event
    switch (message.text) {
        case 'follow':
            break;
        case 'unfollow':
            break;
        case 'join':
            break;
        case 'leave':
            break;
    }
    var isGroup = message.address.conversation.isGroup;
    var txt = isGroup ? "Hello everyone!" : "Hello " + message.from.name;
    var reply = new builder.Message()
        .address(message.address)
        .text(txt);
    bot.send(reply);
    bot.beginDialog(message.address, "hello")
});

bot.dialog("hello", [
    s => {
        builder.Prompts.text(s, "go");
    },
    (s, r) => {
        s.send("oh!" + r.response)
        s.endDialog()
    }
])

License

The MIT license

#If you like this, Welcome to give me Star

2.5.0

5 years ago

2.4.8

5 years ago

2.4.7

5 years ago

2.4.6

5 years ago

2.4.5

5 years ago

2.4.4

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.3.10

5 years ago

2.3.9

5 years ago

2.3.8

5 years ago

2.3.7

5 years ago

2.3.6

5 years ago

2.3.5

5 years ago

2.3.4

6 years ago

2.3.3

6 years ago

2.3.2

6 years ago

2.3.1

6 years ago

2.2.14

6 years ago

2.2.13

6 years ago

2.2.12

6 years ago

2.2.11

6 years ago

2.2.10

6 years ago

2.2.9

6 years ago

2.2.8

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

1.1.1

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago