SlideShare ist ein Scribd-Unternehmen logo
1 von 53
Downloaden Sie, um offline zu lesen
Building more contextual message with
Block Kit
1
@girlie_mac
Hello world!
Tomomi Imura
( @girlie_mac)
2
Quick Intro of Slack API
and
Block Kit
3
Slack: A Collaboration Hub
File
sharing
DevOps
Meetings
Sales /
Analytics
Expense /
Finance
Integration
4
NASA JPL
5
Integration at LA Times
Sharing breaking news
Connecting their CMS with Slack
https://source.opennews.org/articles/slack-buttons/
6
Carter, Popcorn Robot at Nvidia
7
Slack API
8
@girlie_mac
Web APIs
Query information, post messages,
change things! with the Web API.
Use it on the fly for ad-hoc queries or
as part of a more complex tapestry of
platform features.
It's all HTTP-RPC methods and not
quite REST.
Example: chat.postMessage sends a
message
9
@girlie_mac
Events APIs
The Events API is a subscription model for apps
and bots to process & react to activities in Slack.
All you need is a Slack app and a secure place for
Slack to send your events.
Features:
- Events are sent as HTTP requests
- Only subscribe to the events your app needs
- Limit your app’s scopes to only those needed
- Most up to date collection of Slack workspace
and user events
Example: team_join is emitted when a new
member joins your team
10
@girlie_mac
RTM API
The Real Time Messaging API is a
WebSocket-based API that allows you to
receive events from Slack in real time and
send messages as users. It's sometimes
referred to as simply the "RTM API".
Doesn’t require an HTTP server
Does require an always-on websocket
connection
May not contain many newer Slack
Event types, like bot_mention
11
Sending a Simple Message with Web API
12
Hello!chat.postMessage
via HTTP POST
POST /api/chat.postMessage
Content-type: application/json
Authorization: Bearer xoxb-xxxxxxxxx-xxxx
{"channel":"C061EG9SL","text":"Hello!"}
Sending a Styled Message
13
Before...
14
chat.postMessage
{
"channel": "CBADA55JP",
"attachments": [
…
]
}
15
chat.postMessage - attachments
{
"channel": "CBADA55JP",
"attachments": [{
"mrkdwn_in": ["text"],
"color": "#36a64f",
"pretext": "Optional pre-text that appears above the attachment block",
"author_name": "author_name",
"author_link": "http://flickr.com/bobby/",
"author_icon": "https://placeimg.com/16/16/people",
"title": "title",
"title_link": "https://api.slack.com/",
"text": "Optional `text` that appears within the attachment",
"fields": [{
"title": "A field's title",
"value": "This field's value",
}...],
"thumb_url": "http://placekitten.com/g/200/200",
"footer": "footer",
"footer_icon": "https://example.com/default_application_icon.png",
"ts": 123456789 }
]
}
16
Sending a Message with an Attachment
17
chat.postMessage
POST /api/chat.postMessage
Content-type: application/json
Authorization: Bearer xoxb-xxxxxxxxx-xxxx
{"channel":"C061EG9SL","attachment":[......]}
Now with Block Kit
18
Block Kit
● New message UI framework
● Stackable bits of message UI
● Block Kit Builder -
visual prototyping tool
19
Context collection
Image
Text collection
Text
Divider
Thumbnail
Interactive collection
Inline select
Inline overflow
Date picker
20
Basic Block
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello World!"
}
},
{
"type": "divider"
}
]
21
Add Interactivity
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Hello World!"
}
},
{
"type": "divider"
}
"accessory": {
...
}
]
22
[
...
 
"accessory": {
 "type": "button",
 "text": {
"type": "plain_text",
"text": "Farmhouse",
"emoji": true
},
"value": "click_me_123"
 }
]
Add Interactivity
23
Blocks: Section
24
Blocks: Section with Accessory
25
Blocks: Image
26
Blocks: Context
27
Blocks: Actions
28
Blocks: Divider
29
Block Kit Builder
30
Block Kit Builder https://api.slack.com/tools/block-kit-builder
31
Sending a Message with a Block
32
chat.postMessage
POST /api/chat.postMessage
Content-type: application/json
Authorization: Bearer xoxb-xxxxxxxxx-xxxx
{"channel":"C061EG9SL","blocks":[......]}
Doodle (Scheduling App)
33
NaviTime (Japanese Public Transit Finder App)
34
Node.js Example
A Slash Command Result w/ Block Kit
35
+ @/find-food pizza, san francisco
Using Slack API & Yelp API
36
Payload sent via HTTP POST
token=gIkuvaNzQIHg97ATvDxqgjtO
team_id=T0001
team_domain=example
channel_id=C2147483705
channel_name=general
user_id=U2147483697
user_name=girlie_mac
command=/find-food
text=pizza%2C%20san%20francisco
response_url=https://hooks.slack.com/commands/1234/5678
trigger_id=13345224609.738474920.8088930838d88f008e0
37
“pizza, san francisco”
Slash Command Endpoint (Express.js)
const express = require('express');
const app = express();
app.post('/command', async (req, res) => {
// log the payload and see what you got
console.log(req.body);
// reply the command
const message = {
response_type: 'in_channel',
text: replyText
}
res.json(message);
} 38
req.body.text is the slash command
query, “pizza, san francisco”
Reply with a Yelp Restaurant Search Result
app.post('/command', async (req, res) => {
// Extract the slash command query
const query = req.body.text ? req.body.text : 'lunch, San Francisco';
const queries = query.split(',');
const term = queries.shift(); // "Pizza"
const location = queries; // "San Francisco, CA"
const places = await getPlaces(query, location);
const message = {
response_type: 'in_channel',
text: places[0].name
}
res.json(message);
}
Passing the info to Yelp REST
API to get the result in an
array
Sending the result to Slack channel
39
Sending back 200 OK w/ JSON response
const message = {
response_type: 'in_channel',
text: places[0].name
}
res.json(message);
40
By default, it’s ‘ephemeral’
Showing the first result, the
name of the restaurant
Send 200 w/ the message
@girlie_mac
Result (so far, with a plain text)
41
Block-Kit-fy the message
We are going to re-format the JSON message we just created to display a
plain text into this rich message format using Block Kit:
42
BlockKit!
43
Compose Message with Block Kit Builder
2
1
Compose
Copy the
generated
JSON
http://api.slack.com/tools/block-kit-builder
Preview
44
Sending back 200 OK w/ JSON response
const message = {
response_type: 'in_channel',
text: places[0].name
}
res.json(message);
45
Sending back 200 OK w/ JSON response
const message = {
response_type: 'in_channel',
blocks: [
// the message in JSON generated from block kit builder
]
}
res.json(message);
46
const message = {
response_type: 'in_channel',
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*<${places[0].url}|${places[0].name}>* n.. nPrice: ${places[0].price}`
},
accessory: {
type: 'image',
image_url: `${places[0].image_url}`,
alt_text: 'venue image'
}
},
{
'type': 'context',
'elements': [{
'type': 'plain_text',
'text': `${places[0].review_count} Yelp reviews`,
'emoji': true
}]
},
{
'type': 'divider'
},
}
]
};
47
Result w/ Block Kit
48
Tutorial & Source Code
● Tutorial:
https://api.slack.com/tutorials/slash-block-kit
● Source code on Glitch:
https://glitch.com/edit/#!/slash-blockkit
49
@girlie_mac
Resources
★ Slack API Docs: https://api.slack.com
★ Slack events types: https://api.slack.com/events
★ Block Kit: https://api.slack.com/block-kit
★ Block Kit Builder: https://api.slack.com/tools/block-kit-builder
50
51
https://serverless-developer-summit.splashthat.com/
July26th
You’re invited to Spec, a developer conference by Slack.
Learn more at slack.com/spec
Get 30% off registration with code -S19_SPC30
Thank you!
Tomomi Imura (@girlie_mac)
53

Weitere ähnliche Inhalte

Was ist angesagt?

Rest presentation
Rest  presentationRest  presentation
Rest presentation
srividhyau
 

Was ist angesagt? (17)

Flask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuthFlask RESTful Flask HTTPAuth
Flask RESTful Flask HTTPAuth
 
Seaside - The Revenge of Smalltalk
Seaside - The Revenge of SmalltalkSeaside - The Revenge of Smalltalk
Seaside - The Revenge of Smalltalk
 
Rest presentation
Rest  presentationRest  presentation
Rest presentation
 
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREYBUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
 
40+ tips to use Postman more efficiently
40+ tips to use Postman more efficiently40+ tips to use Postman more efficiently
40+ tips to use Postman more efficiently
 
Rest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemyRest API using Flask & SqlAlchemy
Rest API using Flask & SqlAlchemy
 
PHP Function
PHP Function PHP Function
PHP Function
 
Best practices for RESTful web service design
Best practices for RESTful web service designBest practices for RESTful web service design
Best practices for RESTful web service design
 
Designing a beautiful REST json api
Designing a beautiful REST json apiDesigning a beautiful REST json api
Designing a beautiful REST json api
 
Web develop in flask
Web develop in flaskWeb develop in flask
Web develop in flask
 
Using an API
Using an APIUsing an API
Using an API
 
Understanding and testing restful web services
Understanding and testing restful web servicesUnderstanding and testing restful web services
Understanding and testing restful web services
 
Introduction to OAuth 2.0 - Part 1
Introduction to OAuth 2.0 - Part 1Introduction to OAuth 2.0 - Part 1
Introduction to OAuth 2.0 - Part 1
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
How to Leverage APIs for SEO #TTTLive2019
How to Leverage APIs for SEO #TTTLive2019How to Leverage APIs for SEO #TTTLive2019
How to Leverage APIs for SEO #TTTLive2019
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
 
PHP And Web Services: Perfect Partners
PHP And Web Services: Perfect PartnersPHP And Web Services: Perfect Partners
PHP And Web Services: Perfect Partners
 

Ähnlich wie [2019 south bay meetup] Building more contextual message with Block Kit

Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on Kubernetes
Sungwon Lee
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)
Matteo Collina
 

Ähnlich wie [2019 south bay meetup] Building more contextual message with Block Kit (20)

Integrating dialog flow (api.ai) into qiscus sdk chat application
Integrating dialog flow (api.ai) into qiscus sdk chat applicationIntegrating dialog flow (api.ai) into qiscus sdk chat application
Integrating dialog flow (api.ai) into qiscus sdk chat application
 
2012: ql.io and Node.js
2012: ql.io and Node.js2012: ql.io and Node.js
2012: ql.io and Node.js
 
JSON REST API for WordPress
JSON REST API for WordPressJSON REST API for WordPress
JSON REST API for WordPress
 
The Journey to conversational interfaces
The Journey to conversational interfacesThe Journey to conversational interfaces
The Journey to conversational interfaces
 
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
 
Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on Kubernetes
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in Swift
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
 
API Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIsAPI Workshop: Deep dive into REST APIs
API Workshop: Deep dive into REST APIs
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
High quality ap is with api platform
High quality ap is with api platformHigh quality ap is with api platform
High quality ap is with api platform
 
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech TalkContract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
 
Extensible RESTful Applications with Apache TinkerPop
Extensible RESTful Applications with Apache TinkerPopExtensible RESTful Applications with Apache TinkerPop
Extensible RESTful Applications with Apache TinkerPop
 
Office Dev Day 2018 - Extending Microsoft Teams
Office Dev Day 2018 - Extending Microsoft TeamsOffice Dev Day 2018 - Extending Microsoft Teams
Office Dev Day 2018 - Extending Microsoft Teams
 
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1tServerless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
Serverless with Spring Cloud Function, Knative and riff #SpringOneTour #s1t
 
AtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST APIAtlasCamp2014: Introducing the Confluence REST API
AtlasCamp2014: Introducing the Confluence REST API
 
Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)Enter the app era with ruby on rails (rubyday)
Enter the app era with ruby on rails (rubyday)
 
How fiddling with GraphQL enhanced communications between our back and front ...
How fiddling with GraphQL enhanced communications between our back and front ...How fiddling with GraphQL enhanced communications between our back and front ...
How fiddling with GraphQL enhanced communications between our back and front ...
 
Life on Clouds: a forensics overview
Life on Clouds: a forensics overviewLife on Clouds: a forensics overview
Life on Clouds: a forensics overview
 

Mehr von Tomomi Imura

Mehr von Tomomi Imura (20)

ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
ECMeowScript - What's New in JavaScript Explained with Cats (August 14th, 2020)
 
[POST.Dev Japan] VS Code で試みる開発体験の向上
[POST.Dev Japan] VS Code で試みる開発体験の向上[POST.Dev Japan] VS Code で試みる開発体験の向上
[POST.Dev Japan] VS Code で試みる開発体験の向上
 
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう![Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
[Japan M365 Dev UG] Teams Toolkit v4 を使ってみよう!
 
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
[#DevRelAsia Keynote 2020] Developer Centric Design for Better Experience
 
Engineering career is not a single ladder! - Alternative pathway to develope...
Engineering career is not a single ladder!  - Alternative pathway to develope...Engineering career is not a single ladder!  - Alternative pathway to develope...
Engineering career is not a single ladder! - Alternative pathway to develope...
 
Being a Tech Speaker with Global Mindset
Being a Tech Speaker with Global MindsetBeing a Tech Speaker with Global Mindset
Being a Tech Speaker with Global Mindset
 
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
#TinySpec2019 Slack Dev Meetup in Osaka & Tokyo (in Japanese)
 
Slack × Twilio - Uniquely Powering Communication
Slack × Twilio - Uniquely Powering CommunicationSlack × Twilio - Uniquely Powering Communication
Slack × Twilio - Uniquely Powering Communication
 
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
 [2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func... [2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
[2019 Serverless Summit] Building Serverless Slack Chatbot on IBM Cloud Func...
 
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
[TechWorldSummit Stockholm 2019] Building Bots for Human with Conversational ...
 
Building a Bot with Slack Platform and IBM Watson
Building a Bot with Slack Platform and IBM WatsonBuilding a Bot with Slack Platform and IBM Watson
Building a Bot with Slack Platform and IBM Watson
 
[日本語] Slack Bot Workshop + Intro Block Kit
[日本語] Slack Bot Workshop + Intro Block Kit[日本語] Slack Bot Workshop + Intro Block Kit
[日本語] Slack Bot Workshop + Intro Block Kit
 
[DevRelCon Tokyo 2019] Developer Experience Matters
[DevRelCon Tokyo 2019] Developer Experience Matters [DevRelCon Tokyo 2019] Developer Experience Matters
[DevRelCon Tokyo 2019] Developer Experience Matters
 
[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently[DevRel Summit 2018] Because we all learn things differently
[DevRel Summit 2018] Because we all learn things differently
 
[DevRelCon July 2018] Because we all learn things differently
[DevRelCon July 2018] Because we all learn things differently[DevRelCon July 2018] Because we all learn things differently
[DevRelCon July 2018] Because we all learn things differently
 
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
[Japanese] Developing a bot for your workspace 翻訳ボットを作る![Japanese] Developing a bot for your workspace 翻訳ボットを作る!
[Japanese] Developing a bot for your workspace 翻訳ボットを作る!
 
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi [Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
[Forward4 Webinar 2016] Building IoT Prototypes w/ Raspberry Pi
 
Future of the Web with Conversational Interface
Future of the Web with Conversational InterfaceFuture of the Web with Conversational Interface
Future of the Web with Conversational Interface
 
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
[DevRelCon Tokyo 2017] Creative Technical Content for Better Developer Experi...
 
[日本語・Japanese] Creative Technical Content for Better Developer Experience
[日本語・Japanese] Creative Technical Content for Better Developer Experience[日本語・Japanese] Creative Technical Content for Better Developer Experience
[日本語・Japanese] Creative Technical Content for Better Developer Experience
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

[2019 south bay meetup] Building more contextual message with Block Kit

  • 1. Building more contextual message with Block Kit 1
  • 3. Quick Intro of Slack API and Block Kit 3
  • 4. Slack: A Collaboration Hub File sharing DevOps Meetings Sales / Analytics Expense / Finance Integration 4
  • 6. Integration at LA Times Sharing breaking news Connecting their CMS with Slack https://source.opennews.org/articles/slack-buttons/ 6
  • 7. Carter, Popcorn Robot at Nvidia 7
  • 9. @girlie_mac Web APIs Query information, post messages, change things! with the Web API. Use it on the fly for ad-hoc queries or as part of a more complex tapestry of platform features. It's all HTTP-RPC methods and not quite REST. Example: chat.postMessage sends a message 9
  • 10. @girlie_mac Events APIs The Events API is a subscription model for apps and bots to process & react to activities in Slack. All you need is a Slack app and a secure place for Slack to send your events. Features: - Events are sent as HTTP requests - Only subscribe to the events your app needs - Limit your app’s scopes to only those needed - Most up to date collection of Slack workspace and user events Example: team_join is emitted when a new member joins your team 10
  • 11. @girlie_mac RTM API The Real Time Messaging API is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as users. It's sometimes referred to as simply the "RTM API". Doesn’t require an HTTP server Does require an always-on websocket connection May not contain many newer Slack Event types, like bot_mention 11
  • 12. Sending a Simple Message with Web API 12 Hello!chat.postMessage via HTTP POST POST /api/chat.postMessage Content-type: application/json Authorization: Bearer xoxb-xxxxxxxxx-xxxx {"channel":"C061EG9SL","text":"Hello!"}
  • 13. Sending a Styled Message 13
  • 16. chat.postMessage - attachments { "channel": "CBADA55JP", "attachments": [{ "mrkdwn_in": ["text"], "color": "#36a64f", "pretext": "Optional pre-text that appears above the attachment block", "author_name": "author_name", "author_link": "http://flickr.com/bobby/", "author_icon": "https://placeimg.com/16/16/people", "title": "title", "title_link": "https://api.slack.com/", "text": "Optional `text` that appears within the attachment", "fields": [{ "title": "A field's title", "value": "This field's value", }...], "thumb_url": "http://placekitten.com/g/200/200", "footer": "footer", "footer_icon": "https://example.com/default_application_icon.png", "ts": 123456789 } ] } 16
  • 17. Sending a Message with an Attachment 17 chat.postMessage POST /api/chat.postMessage Content-type: application/json Authorization: Bearer xoxb-xxxxxxxxx-xxxx {"channel":"C061EG9SL","attachment":[......]}
  • 18. Now with Block Kit 18
  • 19. Block Kit ● New message UI framework ● Stackable bits of message UI ● Block Kit Builder - visual prototyping tool 19
  • 20. Context collection Image Text collection Text Divider Thumbnail Interactive collection Inline select Inline overflow Date picker 20
  • 21. Basic Block [ { "type": "section", "text": { "type": "mrkdwn", "text": "Hello World!" } }, { "type": "divider" } ] 21
  • 22. Add Interactivity [ { "type": "section", "text": { "type": "mrkdwn", "text": "Hello World!" } }, { "type": "divider" } "accessory": { ... } ] 22
  • 23. [ ...   "accessory": {  "type": "button",  "text": { "type": "plain_text", "text": "Farmhouse", "emoji": true }, "value": "click_me_123"  } ] Add Interactivity 23
  • 25. Blocks: Section with Accessory 25
  • 31. Block Kit Builder https://api.slack.com/tools/block-kit-builder 31
  • 32. Sending a Message with a Block 32 chat.postMessage POST /api/chat.postMessage Content-type: application/json Authorization: Bearer xoxb-xxxxxxxxx-xxxx {"channel":"C061EG9SL","blocks":[......]}
  • 34. NaviTime (Japanese Public Transit Finder App) 34
  • 35. Node.js Example A Slash Command Result w/ Block Kit 35
  • 36. + @/find-food pizza, san francisco Using Slack API & Yelp API 36
  • 37. Payload sent via HTTP POST token=gIkuvaNzQIHg97ATvDxqgjtO team_id=T0001 team_domain=example channel_id=C2147483705 channel_name=general user_id=U2147483697 user_name=girlie_mac command=/find-food text=pizza%2C%20san%20francisco response_url=https://hooks.slack.com/commands/1234/5678 trigger_id=13345224609.738474920.8088930838d88f008e0 37 “pizza, san francisco”
  • 38. Slash Command Endpoint (Express.js) const express = require('express'); const app = express(); app.post('/command', async (req, res) => { // log the payload and see what you got console.log(req.body); // reply the command const message = { response_type: 'in_channel', text: replyText } res.json(message); } 38 req.body.text is the slash command query, “pizza, san francisco”
  • 39. Reply with a Yelp Restaurant Search Result app.post('/command', async (req, res) => { // Extract the slash command query const query = req.body.text ? req.body.text : 'lunch, San Francisco'; const queries = query.split(','); const term = queries.shift(); // "Pizza" const location = queries; // "San Francisco, CA" const places = await getPlaces(query, location); const message = { response_type: 'in_channel', text: places[0].name } res.json(message); } Passing the info to Yelp REST API to get the result in an array Sending the result to Slack channel 39
  • 40. Sending back 200 OK w/ JSON response const message = { response_type: 'in_channel', text: places[0].name } res.json(message); 40 By default, it’s ‘ephemeral’ Showing the first result, the name of the restaurant Send 200 w/ the message
  • 41. @girlie_mac Result (so far, with a plain text) 41
  • 42. Block-Kit-fy the message We are going to re-format the JSON message we just created to display a plain text into this rich message format using Block Kit: 42
  • 44. Compose Message with Block Kit Builder 2 1 Compose Copy the generated JSON http://api.slack.com/tools/block-kit-builder Preview 44
  • 45. Sending back 200 OK w/ JSON response const message = { response_type: 'in_channel', text: places[0].name } res.json(message); 45
  • 46. Sending back 200 OK w/ JSON response const message = { response_type: 'in_channel', blocks: [ // the message in JSON generated from block kit builder ] } res.json(message); 46
  • 47. const message = { response_type: 'in_channel', blocks: [ { type: 'section', text: { type: 'mrkdwn', text: `*<${places[0].url}|${places[0].name}>* n.. nPrice: ${places[0].price}` }, accessory: { type: 'image', image_url: `${places[0].image_url}`, alt_text: 'venue image' } }, { 'type': 'context', 'elements': [{ 'type': 'plain_text', 'text': `${places[0].review_count} Yelp reviews`, 'emoji': true }] }, { 'type': 'divider' }, } ] }; 47
  • 48. Result w/ Block Kit 48
  • 49. Tutorial & Source Code ● Tutorial: https://api.slack.com/tutorials/slash-block-kit ● Source code on Glitch: https://glitch.com/edit/#!/slash-blockkit 49
  • 50. @girlie_mac Resources ★ Slack API Docs: https://api.slack.com ★ Slack events types: https://api.slack.com/events ★ Block Kit: https://api.slack.com/block-kit ★ Block Kit Builder: https://api.slack.com/tools/block-kit-builder 50
  • 52. You’re invited to Spec, a developer conference by Slack. Learn more at slack.com/spec Get 30% off registration with code -S19_SPC30
  • 53. Thank you! Tomomi Imura (@girlie_mac) 53