-
Notifications
You must be signed in to change notification settings - Fork 0
/
OneBot-Niko-Text.py
63 lines (42 loc) · 1.92 KB
/
OneBot-Niko-Text.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
#!/usr/bin/env python3
"""
A Watson assistant text interface.
Copyright (C) 2019 Peter Maar
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import WatsonAssistantV2Utility
import os
DEBUG = True
USER_NAME = 'Peter'
__author__ = 'Peter Maar'
__version__ = '0.2.0'
VERSION = '2019-01-05'
api_path = os.path.normpath('ID/ASSISTANT_API_KEY.txt')
assistant_path = os.path.normpath('ID/ASSISTANT_ID.txt')
API_KEY = str.rstrip(open(api_path).read()) # Load API Key from file, removing trailing whitespace
ASSISTANT_ID = str.rstrip(open(assistant_path).read()) # Load Assistant ID from file, removing trailing whitespace
userInp = '' # Sending empty string will give back the welcome message, so initialize it to that
contextVar = {'skills': {'main skill': {'user_defined': {'person': USER_NAME}}}}
print("Connected. Send exit to disconnect at any time.")
assistant = WatsonAssistantV2Utility.WatsonAssistant(VERSION, API_KEY, ASSISTANT_ID)
# Main Loop
while userInp.lower() != 'exit':
lines, contextVar = assistant.message(userInp, contextVar)
WatsonAssistantV2Utility.display_response(lines)
if DEBUG:
print("------------------")
print(contextVar)
print("------------------")
if userInp.lower().find("bye") != -1:
print("To disconnect, enter 'exit' (no quotes) at any time.", end="")
userInp = input("\n>> ")
assistant.disconnect()