-
Notifications
You must be signed in to change notification settings - Fork 0
/
jarvis.py
66 lines (51 loc) · 1.78 KB
/
jarvis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
import falcon
from falcon_ask import dispatch_request, FalconAskMiddleware, respond, util
from deploy import deploy
def deploy_fn(body):
response = None
end_session = False
directives = [{'type': 'Dialog.Delegate'}]
req = body.get('request', {})
dialog_state = req.get('dialogState')
intent_status = req.get('intent', {}).get('confirmationStatus')
if dialog_state == 'COMPLETED':
directives = []
end_session = True
response = 'OK! You can ask me to deploy your app again sometime.'
if intent_status == 'CONFIRMED':
response = "Yeehaw! You're app is now being deployed."
deploy(
name='insert-app-name',
path='insert-app-src-dir',
image='insert-image-name',
# Get values from "minikube docker-env".
env={
'DOCKER_TLS_VERIFY': '',
'DOCKER_HOST': '',
'DOCKER_CERT_PATH': '',
'DOCKER_API_VERSION': '',
},
)
return respond(response, end_session=end_session, directives=directives)
def unknown_fn(body):
return respond(
"You've found something I don't know yet. Try asking again sometime.",
end_session=True
)
class JarvisResource(object):
intent_maps = {
'DeployIntent': deploy_fn,
'UnknownIntent': unknown_fn,
}
welcome = respond(
"Howdy! I'm Jarvis, I can help you deploy your app.",
end_session=False,
)
def on_post(self, req, resp):
response = dispatch_request(req)
resp.body = json.dumps(response)
app = falcon.API(middleware=[
FalconAskMiddleware(JarvisResource, validate=True),
])
app.add_route('/', JarvisResource())