-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
456 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<aiml> | ||
|
||
<category> | ||
<pattern>*</pattern> | ||
<template> | ||
<sraix service="PROGRAMY"><star /></sraix> | ||
</template> | ||
</category> | ||
|
||
</aiml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
bot: | ||
license_keys: $BOT_ROOT/config/license.keys | ||
|
||
prompt: ">>>" | ||
|
||
initial_question: Hi, how can I help you today? | ||
default_response: Sorry, I don't have an answer for that! | ||
default_response_srai: YEMPTY | ||
empty_string: YEMPTY | ||
exit_response: So long, and thanks for the fish! | ||
exit_response_srai: YEXITRESPONSE | ||
|
||
override_properties: true | ||
|
||
brain: | ||
|
||
# Overrides | ||
overrides: | ||
allow_system_aiml: false | ||
allow_learn_aiml: false | ||
allow_learnf_aiml: false | ||
|
||
# Defaults | ||
defaults: | ||
default-get: unknown | ||
default-property: unknown | ||
default-map: unknown | ||
|
||
# Nodes | ||
nodes: | ||
pattern_nodes: ../../ybot/config/pattern_nodes.conf | ||
template_nodes: ../../ybot/config/template_nodes.conf | ||
|
||
files: | ||
aiml: | ||
files: $BOT_ROOT/aiml | ||
extension: .aiml | ||
directories: true | ||
conversation: | ||
file: /tmp/multibot-conversation.csv | ||
format: csv | ||
delete_on_start: true | ||
properties: $BOT_ROOT/config/properties.txt | ||
preprocessors: $BOT_ROOT/config/preprocessors.conf | ||
postprocessors: $BOT_ROOT/config/postprocessors.conf | ||
|
||
services: | ||
PROGRAMY: | ||
classname: programy.services.programy.ProgramyRESTService | ||
method: GET | ||
host: 0.0.0.0 | ||
port: 8989 | ||
url: /api/v1.0/ask | ||
|
||
kik: | ||
bot_name: servusai | ||
webhook: https://4264d3b1.ngrok.io/incoming | ||
host: 127.0.0.1 | ||
port: 5000 | ||
debug: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
programy.processors.post.mergechinese.MergeChinesePostProcessor | ||
programy.processors.post.denormalize.DenormalizePostProcessor | ||
programy.processors.post.formatpunctuation.FormatPunctuationProcessor | ||
programy.processors.post.formatnumbers.FormatNumbersPostProcessor | ||
programy.processors.post.multispaces.RemoveMultiSpacePostProcessor | ||
programy.processors.post.removehtml.RemoveHTMLPostProcessor | ||
programy.processors.post.consoleformat.ConsoleFormatPostProcessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
programy.processors.pre.normalize.NormalizePreProcessor | ||
programy.processors.pre.removepunctuation.RemovePunctuationPreProcessor | ||
programy.processors.pre.splitchinese.SplitChinesePreProcessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fullname:Y-Bot | ||
|
||
birthdate:March 14, 2017 | ||
|
||
grammar_version:1.0.0 | ||
app_version: 1.0.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
ngrok http 5000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#! /bin/sh | ||
|
||
clear | ||
|
||
export PYTHONPATH=../../../src:. | ||
|
||
python3 ../../../src/programy/clients/kik_client.py --config ./config.yaml --cformat yaml --logging ../../y-bot/logging.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Unit] | ||
Description=Y-Bot Line Client | ||
|
||
[Service] | ||
User=ubuntu | ||
ExecStart=/opt/program-y/bots/servusai/kik/servusai-kik.sh | ||
Restart=always | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#! /bin/sh | ||
|
||
# This file is for use on Servusai.com AWS Server | ||
|
||
export PYTHONPATH=/opt/program-y/src:. | ||
|
||
cd /opt/program-y | ||
|
||
python3 /opt/program-y/src/programy/clients/kik_client.py --config /opt/program-y/bots/servusai/kik/config.yaml --cformat yaml --logging /opt/program-y/bots/y-bot/logging.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@echo off | ||
|
||
CLS | ||
|
||
mkdir .\temp | ||
|
||
SET PYTHONPATH=..\..\src;. | ||
|
||
python ..\..\src\programy\clients\kik_client.py --config .\config.windows.yaml --cformat yaml --logging .\logging.windows.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#! /bin/sh | ||
|
||
clear | ||
|
||
export PYTHONPATH=../../src:. | ||
|
||
python3 ../../src/programy/clients/kik_client.py --config ./config.yaml --cformat yaml --logging ./logging.yaml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
""" | ||
Copyright (c) 2016-17 Keith Sterling http://www.keithsterling.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, | ||
and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the | ||
Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
""" | ||
|
||
# https://kik.readthedocs.io/en/latest/user.html#installation | ||
|
||
import logging | ||
|
||
from flask import Flask, request, abort, Response | ||
|
||
from kik import KikApi, Configuration | ||
from kik.messages import messages_from_json, TextMessage | ||
|
||
from programy.clients.client import BotClient | ||
from programy.config.sections.client.kik_client import KikConfiguration | ||
|
||
|
||
KIK_CLIENT = None | ||
|
||
|
||
class KikBotClient(BotClient): | ||
|
||
def __init__(self, argument_parser=None): | ||
BotClient.__init__(self, "kik", argument_parser) | ||
|
||
self.get_tokens() | ||
|
||
self.create_kik_bot() | ||
|
||
if logging.getLogger().isEnabledFor(logging.DEBUG): | ||
logging.debug("Kik Client is running....") | ||
|
||
def set_environment(self): | ||
self.bot.brain.properties.add_property("env", 'kik') | ||
|
||
def get_client_configuration(self): | ||
return KikConfiguration() | ||
|
||
def get_tokens(self): | ||
self._bot_api_key = self.bot.license_keys.get_key("KIK_BOT_API_KEY") | ||
|
||
def ask_question(self, clientid, question): | ||
response = "" | ||
try: | ||
response = self.bot.ask_question(clientid, question) | ||
except Exception as e: | ||
print(e) | ||
return response | ||
|
||
def create_kik_bot(self): | ||
self._kik_bot = KikApi(self.configuration.client_configuration.bot_name, self._bot_api_key) | ||
self._kik_bot.set_configuration(Configuration(webhook=self.configuration.client_configuration.webhook)) | ||
|
||
def handle_text_message(self, message): | ||
question = message.body | ||
clientid = message.from_user | ||
|
||
answer = self.ask_question(clientid, question) | ||
|
||
self._kik_bot.send_messages([ | ||
TextMessage( | ||
to=message.from_user, | ||
chat_id=message.chat_id, | ||
body=answer | ||
) | ||
]) | ||
|
||
def handle_unknown_message(self, message): | ||
pass | ||
|
||
def handle_message_request(self, request): | ||
|
||
messages = messages_from_json(request.json['messages']) | ||
|
||
for message in messages: | ||
if isinstance(message, TextMessage): | ||
self.handle_text_message(message) | ||
else: | ||
self.handle_unknown_message(message) | ||
|
||
def handle_incoming(self, request): | ||
if not self._kik_bot.verify_signature(request.headers.get('X-Kik-Signature'), request.get_data()): | ||
return Response(status=403) | ||
|
||
self.handle_message_request(request) | ||
return Response(status=200) | ||
|
||
|
||
APP = Flask(__name__) | ||
|
||
|
||
@APP.route('/incoming', methods=['POST']) | ||
def incoming(): | ||
return KIK_CLIENT.handle_incoming(request) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
KIK_CLIENT = KikBotClient() | ||
|
||
print("Kik Client running on %s:%s" % (KIK_CLIENT.configuration.client_configuration.host, | ||
KIK_CLIENT.configuration.client_configuration.port)) | ||
|
||
|
||
if KIK_CLIENT.configuration.client_configuration.debug is True: | ||
print("Kik Client running in debug mode") | ||
|
||
if KIK_CLIENT.configuration.client_configuration.ssl_cert_file is not None and \ | ||
KIK_CLIENT.configuration.client_configuration.ssl_key_file is not None: | ||
context = (KIK_CLIENT.configuration.client_configuration.ssl_cert_file, | ||
KIK_CLIENT.configuration.client_configuration.ssl_key_file) | ||
|
||
print("Kik Client running in https mode") | ||
APP.run(host=KIK_CLIENT.configuration.client_configuration.host, | ||
port=KIK_CLIENT.configuration.client_configuration.port, | ||
debug=KIK_CLIENT.configuration.client_configuration.debug, | ||
ssl_context=context) | ||
else: | ||
print("Kik Client running in http mode, careful now !") | ||
APP.run(host=KIK_CLIENT.configuration.client_configuration.host, | ||
port=KIK_CLIENT.configuration.client_configuration.port, | ||
debug=KIK_CLIENT.configuration.client_configuration.debug) |
Oops, something went wrong.