0% found this document useful (0 votes)
2 views

DEVNET-1056

The document provides an introduction to REST APIs and the creation of Spark Bots, detailing the basics of APIs, their importance, and how to interact with the Cisco Spark API. It includes hands-on activities using tools like Postman and Python, as well as guidance on building and testing chatbots. The agenda covers both REST fundamentals and practical bot development within the Cisco Spark environment.

Uploaded by

toniscrib77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DEVNET-1056

The document provides an introduction to REST APIs and the creation of Spark Bots, detailing the basics of APIs, their importance, and how to interact with the Cisco Spark API. It includes hands-on activities using tools like Postman and Python, as well as guidance on building and testing chatbots. The agenda covers both REST fundamentals and practical bot development within the Cisco Spark environment.

Uploaded by

toniscrib77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 106

Intro to Spark

an introduction to REST APIs and


Creating Spark Bots

Adrienne Moherek and Tessa Mero


DEVNET-1056
Agenda Part 1 (REST Basics and Spark)

• REST API Basics:


• What is an API?
• Why APIs?
• How does it work?

• Tour of Cisco Spark API


• Interactive Documentation Hands-on
• Postman Hands-on
• Python examples
Agenda Part 2 (Build a Spark Bot)

• What are Chat Bots?


• What are the Benefits?
• Integrations vs Bots
• Getting Started with a Collaboration API
• Create a Chat Bot
• Using Cloud9 (c9.io)
• Create Webhook Events
• Test Your Bot!
Who Are We?
Cisco DevNet
• What is Cisco DevNet? • We’re on Facebook and
Twitter @CiscoDevNet
• What is the Purpose?
• We are fun!
• Why do we go to events?

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 6
What is an API?
Application Programming Interface

”It’s a way for two pieces of software to


talk to each other”

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 8
For a long time.. Humans were the only users

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 9
For a long time.. Humans were the only users

2. Software
displays results
in User Interface
(UI)

1. User asks for data


or takes action by
interacting with UI

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 10
But what about when the user is another software
system….
2. Software
returns results
via API

My Software System

1. Software asks for


data or takes action
by interacting with API

Your Software System


DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 11
Why APIs?
Why are API’s so important?

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 13
API Growth from 2000 to 2016
35000
API's
30000

25000

20000

15000 API's

10000

5000

0
2000 2005 2007 2009 2011 2013 2015 2016

Source: 2016 data from nordicapis.com. 2005-2015 data from


rubenverborgh.github.io and 2000-2004 data from blog.cutter.com
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 14
The API is the User Interface for
software systems
APIs are sets of requirements that
govern how one application can talk
to another.
An API is like an electrical outlet.
What would it be like The outlet is a service
to power a hair dryer that conforms to
without an outlet? specifications.
- Open wall - sockets deliver 120
volts of alternating
- Unsheath wires
current (AC)
- Splice wires operating at 60Hz
together
- Sets expectation on
- Understand all the behalf of consuming
wires in the wall devices and
provider.
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 17
An API is like …

An API (Application Programming Interface) is best thought of as a contract


provided by one piece of computer software to another.

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 18
APIs help developers create apps that benefit the
end user.

2. Google Maps Users sees


returns map data list of
via API restaurants
close to
them

1. Yelp asks for Map


Data

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 19
APIs are often referred to as “an engine of
innovation.”

-- Programmable Web

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 20
Web Pages, Requests, Response &
REST APIs
View a Web Page

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 22
View a Web Page
Request
GET /index.htm HTTP/1.1

Response
HTTP 200 OK
<html>

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 23
Common HTTP Status Codes

• 200 OK • 404 Not Found


• 301 Moved Permanently • 500 Internal Server
• 302 Found Error
• 550 Permission Denied
• 307 Temporary Redirect
• 400 Bad Request
• 403 Forbidden

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 24
REST APIs use Request and Response to

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 25
Get Data using an API

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 26
Get Data using an API
API Consumer API Provider
Request
GET /rooms

Response
HTTP 200 OK
{json data}

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 27
Example Spark API Flow

3. My App
Compares
members of a
room with team 4. Users
2. Spark returns members sees diff of
member data via users on
API 1. My App asks team and in
Spark for members room
in a room

Cisco Spark

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 28
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 29
What is so great about REST?
Easy to use:

• In mobile apps
• In console apps
• In web apps
Spark REST APIs
• Rooms
• People
• Memberships
• Messages
How does this work?

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 30
Create Spark Account
Let’s get your computer setup
1. Create an account with Spark - https://www.ciscospark.com/
2. Login to the Spark app - https://web.ciscospark.com
OR
Download the Spark app - https://www.ciscospark.com/downloads.html
3. Bookmark the Spark developer documentation -
https://developer.ciscospark.com
(You will need to login to use the interactive documents)

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 32
Create a Spark Developer Account: developer.ciscospark.com

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 33
http://getpostman.com
• Want to code along? Install POSTMAN now
• Free tool to forge API requests, examine responses

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 34
url query parameters

method

request
headers

status code
response
response headers
body

© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
JSON syntax
• square brackets for lists
• curly braces for objects
• name/value pairs for properties,
separated by commas

• pick an online editor


• http://www.jsonlint.com

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 36
Cisco Spark for Developers
Tour of Cisco Spark APIs
Cisco Spark
Complete & Simple

Message Meeting Call

Secure & Open

Spark for Developers Partner Services Spark Hybrid Services


User Integrations, APIs/SDKs, etc. Interconnect Cloud + Prem

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 38
Spark APIs
Extend Cisco Collaboration Cloud
‘Your App’
now with
Cisco Collab!
GET /People

POST /Memberships

PUT /Rooms

DELETE /Messages

/Teams

/Webhooks

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 39
Cisco Spark API v1
/People /Rooms /Membership /Messages /Teams /Webhooks

GET GET GET GET GET GET


List People List Rooms List Memberships List Messages List Teams List Webhooks

POST POST POST POST POST


Create a Room Create a Membership Create a Message Create a Team Create a Webhook

GET GET GET GET GET GET


Get Person Details Get Room details Get Membership details Get Message details Get Team details Get Webhook details

PUT PUT PUT PUT


Update a Room Update a Membership Update a Team Update a Webhook

DELETE DELETE DELETE DELETE DELETE


Delete a Room Delete a Membership Delete a Message Delete a Team Delete a Webhook

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 40
Demo: List Rooms
Find your Spark Developer Token
Login to developer.ciscospark.com
Copy Developer Token

Go to Documentation  Rooms Developer Token

Turn on “Test Mode”

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 42
List Spark Rooms
API Consumer API Provider
Request
GET /rooms

Response
HTTP 200 OK
{json data}

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 43
Response

Method URL

© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
Same API
Call in
POSTMAN

© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
Demo: Create a room
Create a New Room
API Consumer API Provider
Request
POST /rooms

Response
HTTP 200 OK
{json data}

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 47
Method
URL

Response

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 48
Add people to your room
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
Try to add yourself to your room
 What happened?

Add your neighbor to your room


What happened

Challenge: List memberships for room


DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 51
Cisco Spark for Developers
Spark API calls in Python
Using Python to Make Requests
Do It Yourself … with Postman code assistants
• A benefit of REST is that you can invoke Spark from any language
• Code it yourself
• Or generate code from Postman

• OAuth 2 to inject user API token

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 53
Using Python to Make Requests
Do It Yourself … with Postman code assistants

1. Generate a python skeleton from Postman, 2. Run from the command


line

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 54
Q&A
Build a Spark Bot
Agenda (Build a Spark Bot)

• What are Chat Bots?


• What are the Benefits?
• Integrations vs Bots
• Getting Started with a Collaboration API
• Create a Chat Bot
• Using Cloud9 (c9.io)
• Create Webhook Events
• Test Your Bot!
What You Will Need:

• Cisco Spark API Account:


https://developer.ciscospark.com/
• Create Cloud9 Account: http://c9.io
• JSON Viewer: http://tiny.cc/json-viewer

• C9 Alternative (local tunnels):


Localtunnel.me or ngrok.com
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 58
Objective

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 59
What are Chat Bots?
Clippy!

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 61
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 65
What are the Benefits?
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 67
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 68
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 69
Integrations vs Bots
An integration acts as YOU
and can see and do
the things you can do.

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 71
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 72
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 73
A bot appears as another
member of the room, but
can only see messages
that mention it.
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 74
Getting Started with a Collaboration
API
Have 2 things open in your browser:

1. web.ciscospark.com

2. Developer.ciscospark.com

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 76
Creating a Chat Bot
Click on “My Apps” and Add New (+)

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 78
Select ”Create a Bot”

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 79
Add a Bot Image

http://bit.ly/SparkBot-512x512

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 80
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 81
Copy API Access Token

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 82
Copy API Access Token

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 83
Deploy a bot on Cloud9
c9.io/signup

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 85
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 86
A closer look at the Github URL:

https://github.com/CiscoDevNet/node-sparkbot-
samples.

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 87
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
Install Node.js in Cloud9
• In Cloud9, look at the shell terminal at the bottom.

• Type: “npm install” – The nodejs libraries used by our code


sample get downloaded to your Cloud9 Workspace

• Now go to helloworld.js under “examples”

• Click “Run” at the top

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 89
Create Variables
• Click the ENV button at the bottom right of the Cloud9
Terminal

• Create two variables:


NAME VALUE

DEBUG sparkbot
SPARK_TOKEN yourtokenkeyhere

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 90
© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
Make Your Application Public to Share

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 92
Create Webhook events
DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 94
Create Cisco Spark Webhooks

© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
200 Success!
• Click “Run”

• See a “200/success” displayed – webhook assigned to unique


identifier
• Fired off every time a new message is added to a room your
bot is a member of

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 96
Create Another Webhook
• Receive an event every time our bot is added to a room
• Modify “resource” field: replace “messages” with
“memberships”

• Click “Run” again

• See a ”200 / success” message!

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 97
Test your Cisco Spark Bot
Test Bots Response – type /hello

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 99
Mention your bot in Group rooms

© 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public
Type /hello to test Group chat with bot

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 101
Go Further?
• Add a few breakpoints in helloworld.js, restart in debug mode
• Add some commands. Find samples here:
https://github.com/CiscoDevNet/node-sparkbot-samples
• Note: Lots of nodejs bot frameworks exist for Cisco Spark,
from basic to advanced in various languages.

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 102
Complete Your Online Session Evaluation
• Please complete your Online
Session Evaluations after each
session
• Complete 4 Session Evaluations &
the Overall Conference Evaluation
(available from Thursday) to receive
your Cisco Live T-shirt
• All surveys can be completed via
the Cisco Live Mobile App or the
Don’t forget: Cisco Live sessions will be available
Communication Stations for viewing on-demand after the event at
CiscoLive.com/Online

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 103
Continue Your Education
• Demos in the Cisco campus
• Walk-in Self-Paced Labs
• Lunch & Learn
• Meet the Engineer 1:1 meetings
• Related sessions

DEVNET-1056 © 2017 Cisco and/or its affiliates. All rights reserved. Cisco Public 104
Thank You

You might also like