Skype bot microsoft bot framework

12 95 0
Skype bot microsoft bot framework

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Tạo Skype Bot với Microsoft Bot Framework 02 February 2017 bot, skype KYO Bài viết gồm có mục sau: • Microsoft bot framework: giới thiệu Microsoft bot framework cơng cụ kèm • Bot Builder SDK: giới thiệu SDK dùng để phát triển bot web service • Tạo bot nhắc nhở TODO cho ae công ty: Giới thiệu hướng phát triển bot sử dụng cơng ty • Kết luận link tham khảo Microsoft Bot Framework Framework bao gồm: • Bot Builder SDK: SDK NET NodeJS để phát triển tính cho botBot Connector: service giúp cho bạn kết nối với bot bạn thông qua việc thiết lập channel Đóng vai trò trung gian - Forward message bot tới user • Send back message user tới bot • Developer Portal: https://dev.botframework.com, config bot bạn • Bot Directory: chung cấp bot phát triển để ta lấy dùng • Bot Emulator: để test bot trình dev Bot gì? Bot web service tương tác với user qua hội thoại thông qua chanel thiết lập sẵn (ext/SMS, Skype, Slack, Facebook Messenger,…) • Thiết lập hội thoại tự do, sử dụng tương tác ngôn ngữ tự nhiên hay tương tác former thơng qua user choices hay actions • Cuộc hội thoại simple text strings công cụ phức tạp rich cards chứa text, images, action buttons (hero card, thumb card, ) Microsoft cung cấp SDK cho NET NodeJS, với ngơn ngữ khác sử dụng RESTAPI để tương tác với Bot Connector • SDK cho bot open source, bạn xem BotBuilder • Các ví dụ xem BotBuilder-Samples Cơ chế hoạt động bot Bots: bot phát triển, thực web service Developer Portal Microsoft có yêu cầu web service phải HTTPS Bot Connector: route message user bot thông qua channel Skype, Slack, Facebook Messager,… Các channel config Developer Portal Logic hoạt động bot Logic đơn giản có: • Automation todo messaging: vào 8h sáng 17h hàng ngày gửi list todo vào group skype công ty (sử dụng node cron để lập lịch) • Khi member group muốn biết list todo gõ @ todo -> bot post list todo Bot Builder SDK Trong viết giới thiệu SDK NodeJS, để sử dụng SDK NodeJS đâu tiên ta phải cài NodeJS Install NodeJS + Add thư viện Bot Builder (CentOS) Cài node: $ sudo yum install nodejs npm Cài package Bot Builder: $ npm init $ npm install save botbuilder restify • botbuilder: SDK Microsoft Bot Framework • restify: package làm web service Thử làm "Hello World": var restify = require('restify'); var builder = require('botbuilder'); //======================================================== = // Bot Setup //======================================================== = // Setup Restify Server var server = restify.createServer(); server.listen(process.env.port || process.env.PORT || 3978, function () { console.log('%s listening to %s', server.name, server.url); }); // Create chat bot var connector = new builder.ChatConnector({ appId: process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD }); var bot = new builder.UniversalBot(connector); server.post('/api/messages', connector.listen()); //======================================================== = // Bots Dialogs //======================================================== = bot.dialog('/', function (session) { session.send("Hello World"); }); Khởi động bot: $ node app.js Cài Bot Emulator để test: hướng dẫn Khởi động Bot Emulator thiết lập: • URL web service bot • Ấn connect Chat thấy Hello World • Phần Details bên cạnh có lược sử request + response nội dung request để giúp ta debug cho bot Giải thích ví dụ Hello World Khởi tạo bot: • Khởi tạo web server: • // Setup Restify Server • var server = restify.createServer(); • server.listen(process.env.port || process.env.PORT || 3978, function () { • console.log('%s listening to %s', server.name, server.url); • }); • • server.post('/api/messages', connector.listen()); Sử dụng restify để tạo web server để xử lý tương tác với user • Thiết lập connector: có loại ConsoleConnector (tương tác với bot thông qua console, ko cần web server trên) ChatConnector (tương tác với bot trông qua emulator channel) • // Setup Restify Server • var server = restify.createServer(); • server.listen(process.env.port || process.env.PORT || 3978, function () { • console.log('%s listening to %s', server.name, server.url); • }); • • server.post('/api/messages', connector.listen()); process.env.MICROSOFT_APP_ID, appPassword: process.env.MICROSOFT_APP_PASSWORD thông tin App tạo Microsoft Developer Portal, cần thiết chạy production, emulator ko cần • Thiết lập bot: var bot = new builder.UniversalBot(connector); //======================================================== = // Bots Dialogs //======================================================== = bot.dialog('/', function (session) { session.send("Hello World"); }); UniversalBot não bot, quản lý hội thoại bot user qua việc định nghĩa dialogs Quản lý Dialogs để tương tác với users Message Type Bot Builder SDK hỗ trợ loại message: • Reactive Messages (message phản ứng): response message bot cho user nhận message từ user, thông thường gửi qua method session.send() • Proactive Messages (message chủ động): message tự động gửi từ bot đến user mà không cần user tương tác với bot, ví dụ bot skype gửi list todo hàng ngày vào 8h sáng Proactive Messages send thông qua phương thức bot.send() bot.beginDialog() lớp UniversalBot, để gửi message chủ động ta cần thông tin address nơi mà ta muốn bot gửi message đến Ta lấy liệu address thơng qua session.message.address Sẽ có dạng sau: address: { id: '1485306 ', channelId: 'skype', user: { id: '29:10ZkF7DJz3CCiwAQKdodDjaoFlXJGS16 ', name: '【GMO【VNLAB Hieu Tran' }, conversation: { isGroup: true, id: '19:e9b1e1da29a9473e990353354ebbd393@thread.skype' }, bot: { id: '28:a23cbb4d-61e8-4143-8f5f -', name: 'jarvis' }, serviceUrl: 'https://skype.botframework.com', useAuth: true } Trong đó: • address.channelId: kênh mà ta thiết lập Developer Portal • address.user: chứa thông tin user tương tác với ta • address.conversation: thơng tin quan trọng để gửi message chủ động chưa conversation id để gửi message • address.bot: thơng tin bot • address.serviceUrl: url channel Đoạn code sau đoạn code gửi message chủ động thông qua request lên web server server.post('/api/notify', function (req, res) { // Process posted notification var address = JSON.parse(req.body.address); var notification = req.body.notification; // Send notification as a proactive message var msg = new builder.Message() address(address) text(notification); bot.send(msg, function (err) { // Return success/failure res.status(err ? 500 : 200); res.end(); }); }); Trong đó: • var address = JSON.parse(req.body.address);: lấy thông tin address từ boby request ( tức http request chứa thông tin conversation mà muốn bot gửi message tới) • Sau có thơng tin address ta cần sử dụng method bot.send() để gửi message Cards Buttons Trong skype ta tạo Card hay Button thay cho text message Các loại card hỗ trợ: • Hero card • Thumbnail card • Video card • Audio card • Animated GIF card • Carousel card (with hero or thumbnail images) • Sign in card • Receipt card Các card button giúp người dùng tương tác thêm sinh động với bot Các bạn xem thêm link Tạo bot nhắc nhở TODO Yêu cầu Quản lý lịch TODO cơng ty, bao gồm: • List task • Người chịu trách nhiệm • Hạn phải hồn thành Tương lai: • Alert task gấp • Tăng tính tương tác o Vote o Tra cứu thông tin cần thiết o Nếu làm cty Nhật liên quan tới Nhật thấu hiểu tình cảnh có nhiều việc lặt vặt, không mang lại giá trị cho công ty, cá nhân ta phải làm hàng ngày, tốt để giải cách đơn giản, ko bị ảnh hưởng tới việc có giá trị cao ta phải tự động hoá việc vặt vãnh Con bot với mục đích đẩy để giảm bớt gánh nặng cho ae công ty Hướng giải Sử dụng Microsoft Bot làm bot thông qua skype để ngày vào 8h sáng (giờ cty bắt đầu làm việc) nhắc nhở todo list cho anh em cty Data source: sử dụng Trello (tool trực quan hố cơng việc thẻ card), lý tơi dùng trello làm data source độ trực quan cao, thao tác dễ, tương tác = API đơn giản Vấn đề Scheduling: sử dụng node cron Quản lý nodejs service: PM2 Trình tự thực thi Tạo app Application Registration Portal Microsoft Lấy AppId App Secret để config cho bot Tạo bot Developer Portal: link Config AppId App Secret tạo Config thông tin sau bot o Messaging endpoint: phải https (trong TH https://longkyo.com/api/messages) o Name o Icon Add Skype Channel Developer Portal Edit Skype Channel enable group Group messaging để bot tương tác với group skype Add bot vào skype Developer Portal Add bot vào group skype 10 Config cho bot thông số: o Skype conversation id o Trello list id Cơ chế hoạt động Tổng quan sơ đồ hoạt động List todo lấy từ list Trello: Nội dung todo bao gồm: • Tên task: title card • Member: member assign card • Due date: due date card • Note: lấy từ description card ( theo json format ) Kết luận Đặc điểm bật: • Sử dụng Microsoft Bot Framework giúp ta linh động việc lựa chọn channel để tương tác với người dùng • Sử dụng trello làm data source giúp trực quan hoá tối đa task todo cơng ty • Giảm thời gian quản lý task todo giúp ae quên task todo phải làm Hướng phát triển cho trương lai: • Phát triển AI cho bot xử lý ngôn ngữ tự nhiên (natural language processing) • Phát triển thêm nhiều tính tự động là: • o Alert liên tục task khẩn cấp o Alert cuối tháng nhập time cho redmine o Chúc mừng sinh nhật ae cty o Notify channel Facebook messager (hiện chưa hỗ trợ add bot vào group) • Tham khảo • https://docs.botframework.com/en-us/ • https://developers.trello.com/advanced-reference • Các bạn thuộc VNLAB xem source GitLab ... Add Skype Channel Developer Portal Edit Skype Channel enable group Group messaging để bot tương tác với group skype Add bot vào skype Developer Portal Add bot vào group skype 10 Config cho bot. .. Cơ chế hoạt động bot Bots: bot phát triển, thực web service Developer Portal Microsoft có yêu cầu web service phải HTTPS Bot Connector: route message user bot thông qua channel Skype, Slack, Facebook... node: $ sudo yum install nodejs npm Cài package Bot Builder: $ npm init $ npm install save botbuilder restify • botbuilder: SDK Microsoft Bot Framework • restify: package làm web service Thử

Ngày đăng: 22/03/2019, 08:15

Mục lục

    Tạo Skype Bot với Microsoft Bot Framework

    Cơ chế hoạt động của bot

    Logic hoạt động của bot

    Install NodeJS + Add thư viện Bot Builder (CentOS)

    Giải thích ví dụ Hello World

    Tạo bot nhắc nhở TODO

    Trình tự thực thi

    Cơ chế hoạt động

Tài liệu cùng người dùng

Tài liệu liên quan