Slide 1

Slide 1 text

M E S S A G I N G B O T I N T R O D U C T I O N S O F JOHNNY SUNG 2016.06.18 @ GDG Kaohsiung

Slide 2

Slide 2 text

MOBILE DEVICES DEVELOPER Johnny Sung https://fb.com/j796160836 https://plus.google.com/+JohnnySung http://about.me/j796160836

Slide 3

Slide 3 text

Ӟ㮆ਁ犋㾏珥牧ᐟ褺 ᴨਡ 䌕肬物೉蝀搴

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

http://i57.tinypic.com/2wfo8rl.png

Slide 6

Slide 6 text

http://cdn1.bigcommerce.com/server3400/v4eyu8t/products/1722/images/2350/Essential_NPC_1__63835.1427321112.1280.1280.jpg

Slide 7

Slide 7 text

獺 ఺ 咳 మ 物 ֦ ૶ 磭 ਙ 狶 Ջ 讕 牫 http://www.jeanchristophebonis.com/wp-content/uploads/2015/01/5949_render_walle4.png

Slide 8

Slide 8 text

ᮎ 圵 秚 瑊 Ո 牫 • 蝢Ꭳ觊 • Git ጱ commit, pull request 蝢Ꭳ • Server deploy 蝢Ꭳ • Ո㹓藶؃蝢Ꭳ牏ᤈԪ磓蝢Ꭳ • 蝱虴蝢Ꭳ • …

Slide 9

Slide 9 text

ᮎ 圵 秚 瑊 Ո 牫 • ԰㵕觊 (൉׀虻懱౲㵕֢) • 懪瞆牏懪觵ମ牏懪׎吚 (?) • 搚疑ᛔ㵕ࢧ薟 • 渟楮൉蠣 • …

Slide 10

Slide 10 text

虻碘㬵რ物
 http://www.ettoday.net/news/20141231/445744.htm

Slide 11

Slide 11 text

https://www.facebook.com/DoctorKoWJ/photos/a.415511451884174.1073741827.136845026417486/574861115949206

Slide 12

Slide 12 text

S L A C K

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

S L A C K • Incoming Webhooks • Send messages into Slack with customization and rich formatting. • Outgoing Webhooks • Send messages from Slack to your service in real-time. • Bot Users • Connect to Slack to read and write as a real-time bot.

Slide 16

Slide 16 text

I N C O M I N G W E B H O O K S https://api.slack.com/incoming-webhooks Your server Slack POST 200 OK

Slide 17

Slide 17 text

curl -X POST -H 'Content-type: application/json' --data ‘{“text”:"Hello, World!”}’ https://hooks.slack.com/services/T00000000/B00000000/ XXXXXXXXXXXXXXXXXXXXXXXX I N C O M I N G W E B H O O K S https://api.slack.com/incoming-webhooks 涮鷑鎝䜂

Slide 18

Slide 18 text

I N C O M I N G W E B H O O K S https://api.slack.com/incoming-webhooks

Slide 19

Slide 19 text

• Trigger keyword(s) • Callbacks • Cons: Public channel only O U T G O I N G W E B H O O K S https://api.slack.com/outgoing-webhooks

Slide 20

Slide 20 text

O U T G O I N G W E B H O O K S https://api.slack.com/outgoing-webhooks Slack 1. Detect if have certain keyword ͩΩ΁ͷ΅ Bonjour উ֞ೞࣁਃ สวัสดี ֦অ नमस्ते မဂ#လ%ပ'

Slide 21

Slide 21 text

O U T G O I N G W E B H O O K S https://api.slack.com/outgoing-webhooks Slack Your Server 200 OK 2. POST user message POST

Slide 22

Slide 22 text

O U T G O I N G W E B H O O K S https://api.slack.com/outgoing-webhooks Slack Your Server 200 OK POST 3. Return bot message

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

B O T U S E R S ( R E A L T I M E M E S S A G I N G A P I ) https://api.slack.com/bot-users Your server Slack WebSocket

Slide 25

Slide 25 text

https://api.slack.com/bot-users Your server Slack WebSocket Hello User Online User Typing Messages… B O T U S E R S ( R E A L T I M E M E S S A G I N G A P I )

Slide 26

Slide 26 text

https://api.slack.com/bot-users Your server Slack WebSocket Hello User Online User Typing Messages… B O T U S E R S ( R E A L T I M E M E S S A G I N G A P I )

Slide 27

Slide 27 text

https://api.slack.com/rtm More info:

Slide 28

Slide 28 text

https://api.slack.com/bot-users Your server Slack WebSocket Post Messages Bots Info Users Info… B O T U S E R S ( R E A L T I M E M E S S A G I N G A P I )

Slide 29

Slide 29 text

https://api.slack.com/methods More info:

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

https://github.com/slackhq/python-slackclient * pip required

Slide 33

Slide 33 text

#!/usr/bin/python
 # -*- coding: utf-8 -*-
 
 import time
 from slackclient import SlackClient
 # Token found at https://api.slack.com/web#authentication
 token = "xoxb-52095439187-CYPqixxxxxzwR9MoriR"
 sc = SlackClient(token)
 if sc.rtm_connect():
 while True:
 results = sc.rtm_read()
 for result in results:
 if 'type' in result:
 if result['type'] == u'message' and not('subtype' in result):
 channel = result['channel']
 text = result['text']
 user = result['user']
 if channel != u'C02HKPG5U' and user != u'U1J2TCX5H': # Filter out:
 # C02HKPG5U ==> General channel
 # U07SJTAMC ==> Bot it's self
 try:
 sc.rtm_send_message(channel, text)
 except Exception, e:
 print e 
 print result
 time.sleep(5)
 else:
 print "Connection Failed, invalid token?" Python

Slide 34

Slide 34 text

{u'text': u’Hello, world!’, u'ts': u'1466228461.000005', u'user': u'U02HKPG5G', u'team': u'T02HKPG5C', u'type': u'message', u'channel': u'G1J4EADCH'} {u'type': u'hello'} {u'type': u'presence_change', u'user': u'U1J4C9FGF', u'presence': u'active'} )FMMP鎝䜂 ♳箁朜䢀隶刿 倞鎝䜂

Slide 35

Slide 35 text

L I N E

Slide 36

Slide 36 text

https://developers.line.me/bot-api/overview

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

SSL Certificate

Slide 40

Slide 40 text

https://developers.line.me/bot-api/getting-started-with-bot-api-trial Your server Line L I N E B O T Messages https://

Slide 41

Slide 41 text

https://developers.line.me/bot-api/getting-started-with-bot-api-trial Your server Line Post Messages L I N E B O T

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

https://developers.line.me/bot-api/getting-started-with-bot-api-trial

Slide 45

Slide 45 text

POST /linebot.php HTTP/1.1 ACCEPT: */* ACCEPT-CHARSET: utf-8 CONTENT-TYPE: application/json;charset=UTF-8 USER-AGENT: ChannelEventDispatcher/1.0 X-LINE-CHANNELSIGNATURE: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CONTENT-LENGTH: 542 HOST: your.ip.here:443 CONNECTION: Keep-Alive ACCEPT-ENCODING: gzip,deflate {“result”:[{"content":{"toType":1,"createdTime": 1465701674031,"from":"u2832cfc217c72c6df812248d041b73c8","location":null,"id":"4450389 514583","to":["uc6b4b8ef65ce03b72a672ac34b6e3a60"],"text":"Hello, World!”,”contentMetadata": {"AT_RECV_MODE":"2","EMTVER":"4","SKIP_BADGE_COUNT":"true"},"deliveredTime": 0,"contentType":1,"seq":null},"createdTime": 1465701674063,"eventType":"138311609000106303","from":"u206d25c2ea6bd87c17655609a 1c37cb8","fromChannel":1341301815,"id":"WB1521-3505347188","to": ["uc6b4b8ef65ce03b72a672ac34b6e3a60"],"toChannel":1463624852}]} https://developers.line.me/bot-api/getting-started-with-bot-api-trial 佐ⵌ鎝䜂涸㼓⺫

Slide 46

Slide 46 text

https://developers.line.me/bot-api/getting-started-with-bot-api-trial

Slide 47

Slide 47 text

"https://trialbot-api.line.me/v1/events",
 CURLOPT_HEADER => 0,
 CURLOPT_VERBOSE => 0,
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_POST => true,
 CURLOPT_POSTFIELDS => array(
 "to" => $toIdArr,
 "toChannel" => 1383378250,
 "eventType" => "138331608800106203",
 "content" => array(
 "contentType" => 1,
 "toType" => 1,
 "text" => $message
 ),
 ),
 CURLOPT_HTTPHEADER => array(
 'X-Line-ChannelID: 1463624852',
 'X-Line-ChannelSecret: 4968a9430a32c10d969e395acd04117f',
 'X-Line-Trusted-User-With-ACL: uc6b4b81e65ce03b72a672ac34b6e3a60',
 'Content-type: application/json; charset=UTF-8',
 )
 );
 
 curl_setopt_array($curl, $options);
 $result = curl_exec($curl);
 curl_close($curl);
 return $result;
 } 涮鷑鎝䜂 PHP

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

https://github.com/line/line-bot-sdk-php * composer required

Slide 50

Slide 50 text

FA C E B O O K M E S S E N G E R

Slide 51

Slide 51 text

皃 㮆 犋 梊 ጱ 塅 ֺ • CNN • https://www.facebook.com/cnn/ • Humani: Jessie's Story • https://www.facebook.com/JessieHumani/

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

Your server Facebook M E S S E N G E R B O T Messages https:// https://messengerplatform.fb.com/

Slide 56

Slide 56 text

Your server Post Messages M E S S E N G E R B O T https://messengerplatform.fb.com/ Facebook

Slide 57

Slide 57 text

C R E AT I N G M E S S E N G E R B O T • 1. Create a Facebook App and Page • 2. Setup Webhook • 3. Get a Page Access Token • 4. Subscribe the App to the Page https://messengerplatform.fb.com/

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

YOUR_VERIFY_TOKEN

Slide 63

Slide 63 text

https://developers.facebook.com/docs/graph-api/webhooks

Slide 64

Slide 64 text

4 . S U B S C R I B E T H E A P P T O T H E PA G E curl -X POST "https://graph.facebook.com/v2.6/me/ subscribed_apps?access_token=" 䁆ᤈ瞲犤

Slide 65

Slide 65 text

No content

Slide 66

Slide 66 text

POST /fbbot/main.php HTTP/1.1 HOST: your.ip.here ACCEPT: */* ACCEPT-ENCODING: deflate, gzip CONTENT-TYPE: application/json X-HUB-SIGNATURE: sha1=03xxxxxxxxxxxxxxxxxxxxxxxxd58a7 CONTENT-LENGTH: 261 {"object":"page","entry":[{"id":1010700000009448,"time": 1460599788132,"messaging":[{"sender":{"id":1006290000095540},"recipient": {"id":1010710000019448},"timestamp":1460000088101,"message": {"mid":"mid.1460000088087:e7dca9a000001d9e91","seq":15,"text":"hi"}}]}]} 佐ⵌ鎝䜂涸㼓⺫

Slide 67

Slide 67 text

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

array(
 "id" => $toId
 ),
 "message" => array(
 "text" => $message
 )
 )
 );
 
 $pageToken = "YOUR_PAGE_TOKEN";
 
 $ch = curl_init();
 $options = array(
 CURLOPT_URL => "https://graph.facebook.com/v2.6/me/messages?access_token=" . $pageToken,
 CURLOPT_HEADER => 0,
 CURLOPT_VERBOSE => 0,
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_POST => true,
 CURLOPT_POSTFIELDS => $post,
 CURLOPT_HTTPHEADER => array(
 'Content-type: application/json; charset=UTF-8'
 )
 );
 
 curl_setopt_array($ch, $options);
 $result = curl_exec($ch);
 curl_close($ch);
 return $result;
 } PHP 涮鷑鎝䜂

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

S K Y P E

Slide 72

Slide 72 text

Your server Skype S K Y P E B O T https://developer.microsoft.com/en-us/skype/bots/docs/api/chat Messages https://

Slide 73

Slide 73 text

Your server Skype Post Messages S K Y P E B O T https://developer.microsoft.com/en-us/skype/bots/docs/api/chat

Slide 74

Slide 74 text

S K Y P E B O T • 1. Create Skype bot • 2. Create Microsoft Application • 3. Paste Application ID to Skype bot • 4. Add your bot to contact https://developer.microsoft.com/en-us/skype/bots/docs/api/chat

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

T H E R E S O U R C E M O D E L Conversation ID • 8: • 28: • 19: • …. https://developer.microsoft.com/en-us/skype/bots/docs/api/chat

Slide 82

Slide 82 text

https://github.com/radutopala/skype-bot-php * composer required

Slide 83

Slide 83 text

https://developer.microsoft.com/en-us/skype/bots/docs/api/chat

Slide 84

Slide 84 text

POST /skypebot/main.php HTTP/1.1 CONTENT-TYPE: application/json; charset=utf-8 HOST: your.ip.here CONTENT-LENGTH: 156 EXPECT: 100-continue CONNECTION: Keep-Alive [{"id":"0","content":"Hi","activity":"message","from":"8:USERNAME","to":"28 :BOTID","time":"2016-06-16T07:08:03.906Z"}] 佐ⵌ鎝䜂涸㼓⺫

Slide 85

Slide 85 text

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

https://developer.microsoft.com/en-us/skype/bots/docs/api/chat

Slide 88

Slide 88 text

'YOUR_CLIENT_ID',
 'clientSecret' => 'YOUR_CLIENT_SECRET',
 ]);
 $api = $client->authorize()->api('conversation');
 $result = $api->activity($id, $message);
 return $result;
 } PHP 涮鷑鎝䜂

Slide 89

Slide 89 text

No content

Slide 90

Slide 90 text

Q & A http://www.britishacademyforonlinelearning.com/wp-content/uploads/2015/10/qanda.png

Slide 91

Slide 91 text

https://www.facebook.com/kobeengineer/posts/1777258705843732:0

Slide 92

Slide 92 text

https://www.facebook.com/groups/chatbot.tw/ Chatbot Developers Taiwan 稭蜰ے獈 http://freeiconbox.com/icon/256/34429.png

Slide 93

Slide 93 text

(ੜ肨㺔) మ䋊腀承牫

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

ݣ 傀 腀 承 䒍 肥 ፑ https://www.facebook.com/groups/155659364581944/ 稭蜰ے獈

Slide 96

Slide 96 text

No content