Skip to content

Commit

Permalink
started working on python api
Browse files Browse the repository at this point in the history
  • Loading branch information
tatanpoker09 committed Sep 16, 2022
1 parent cc10f7d commit 0eb0a3c
Show file tree
Hide file tree
Showing 57 changed files with 180 additions and 133 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Expand Up @@ -226,7 +226,7 @@ $RECYCLE.BIN/
bin/
integrations/*/.idea/
.env
journey_bot/.env
channels/journey_bot/.env
journey_central/.idea/
journey_central/.jython_cache/
journey_central/treeassistant-tatan.json
Expand All @@ -236,9 +236,9 @@ journey_core_nlp/.generated/
journey_core_nlp/__pycache__/
journey_core_nlp/elasticsearch-7.8.0/*
*/.env
journey_speech/__pycache__/
journey_speech/.env
journey_speech/treeassistant-tatan.json
channels/journey_speech/__pycache__/
channels/journey_speech/.env
channels/journey_speech/treeassistant-tatan.json
lib/
log/
venv/
Expand Down
36 changes: 24 additions & 12 deletions journey_bot/bot_starter.py → channels/journey_bot/main.py
@@ -1,16 +1,16 @@
import logging
import os
import mindmeld

from dotenv import load_dotenv
from telegram.ext import (
Updater,
CommandHandler,
MessageHandler,
Filters,
ConversationHandler,
CallbackContext,
)
import logging
import requests
from dotenv import load_dotenv

from channels.voice import JourneyChannel

url = "http://localhost:7150/parse"

Expand All @@ -21,22 +21,34 @@
level=logging.INFO)
dispatcher = updater.dispatcher

bot_channel = JourneyChannel(__name__)


class TelegramBot:
def __init__(self):
pass


def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Hello, I'm Journey. What can I do for you?")


def message_received(update: Updater, context: CallbackContext):
def telegram_message_received(update: Updater, context: CallbackContext, channel: JourneyChannel):
msg = update.message.text
body = {"text": msg}
response = requests.post(url, json=body)
print(response.json())
context.bot.send_message(chat_id=update.effective_chat.id, text=response.json()["directives"][0].payload.text)
dialogue_id = channel.process_message(msg)
session = channel.get_session(dialogue_id)
session.chat_id = update.effective_chat.id
session.context = context


message_handler = MessageHandler(Filters.text, message_received)
dispatcher.add_handler(message_handler)
@bot_channel.process_message
def process_message(session, message):
context = session.context
context.bot.send_message(chat_id=session.chat_id, text=message)


message_handler = MessageHandler(Filters.text, lambda x, y: telegram_message_received(x, y, bot_channel))
dispatcher.add_handler(message_handler)
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions channels/journey_speech/google-application-credentials.json
@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "treeassistant-tatan",
"private_key_id": "c17762b3284ad4b2892da86b5acad31d81456480",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCxPkpEu2F/AgfT\nRN1E6d3AWKuUlN6EvWtbMkzJBTVPNE3dHNYwmXv+BdiPr63ZBIruRGngkzmlTWmA\nBnXzxL62ddyUUAGMix0Ei6iI9Dd31YUf8fpxfoesckoTVPVygIVjxaN9a3Bp3vl5\nHffGcMYCJqUjEempno0B4OM+d4NY4Z7giBkUrTJ1OPKWFwJm0EGHVoO+mmMLlnoj\ny4ybKlxzbY67jFRD6x4Ua9q5G3D19h2Xi1GnySIKhwCGRCcl6CIPJr0hJxyBzHS0\ny40QnBPYLL9cM8t8bUuMMvjWyz8On075aEyaUuqSrUE8aLn5vFBSiKHG6f+UFi/8\nW+YwEmxzAgMBAAECggEAB+t3a7ICKnSvkm2MHZCXPtY3d7PEBaMyvg51ukqOfHPv\n240QUERrcyK7vIZMrfSZm9ZYWZdg7Tv6SaUAQqlsUPOo3/YU1TzaFq8brSyMb430\nHUTovFPuqAv4HckFqd1VGIVnFF5nbxoH6uhZGMR6DidZgnZ1PgXYDL9wKAU0snuM\nHhr9DlvPeqh7Y6ghU11wTHEobZV5Ys9Kiz4cekWYKRe4/8yaYHOPThCOIMVukS5q\nxekTIkIcciFOSAqQ7g4U+PILf1+9ZxDbtsdLs0s5R37v8o7YpCxvFaZ6zNxAHrbS\noFrLi2hOUb1deFw5H1a2wADDR/UbcHAlgIj+Vl36cQKBgQDlS6slj52OXNHqiWar\nGkBwbVU9eBKOIT6G6TVSZEfVhUCB5eU+A+zofEnHxoeI6os7JcdW5SBzn7p7tJwN\nBgtvSFF0DLUMVGhyLH6VfCCLC9HsmY0b5f8Nf/+KJz3oZIADcLgtwK7cZwROGTVF\n9I5SxSq/5Y+P9CT82O9Bf7XQ1wKBgQDF4rW4eyjMDsE1orVKXr+K3ItAcOKg5LCC\np83iwtrmt6LiSRTe6JQsSmlkRZhV0z4zFjKqoyYem6u3yhCAUPk2V00vx2hy9gxz\nuGXtY0WZRnGZ4HG+mscORi5JpHr28WjJCSQDUA4jCtpJ4cSUizDikHOXDlKw4TGL\nweP7gAshxQKBgQCyrRVPrqrq7b+SEMHVYR6HvVroDHIBGTy9KmsnqgckBrMuxfOu\nMKbivz9LEpQ5B/O5AoZkWyW/k99gWGwl5ejxLZxzXxeR5RCCr9NwLwq471wFD96a\nt83ZOj3p7Qxb1DzA8YxD8tsP2qLLLO+LdLeXHhdi88K8PVa5RV6jXp5SfwKBgQCs\nQ/wmKTEO0xlnc8mWgH0GiY+//YWMwwjV9PbKnQ6rItntW+mLU7UKCY1N+TfwHwFa\nv8xDt9uLccE/MezDh7orkDxlh5Zp3cBhTPmOeokwMZ7bcgQTBfKbfoT1Hvbc2rN5\nrzdmmt5zqxL0llHnbnSUB2RY7+MUkDXtkFDDtGf8cQKBgQCAescmKqvwC+rXJb1c\nU+HOS9DJMzQzjI54MZqgfjcN68C1zm8Y6TZ9lBGkkGHOoRVolCY5QLTrgeFzCoTC\ns+uhss9CEewRJs8OxxfnAr373JG8ZiGIrw4PHFG3hlPiCCNKoOarEhWT09EAOPY0\ng/LjdJToLWRghp3sFC4v6FUKTA==\n-----END PRIVATE KEY-----\n",
"client_email": "treetester@treeassistant-tatan.iam.gserviceaccount.com",
"client_id": "109961751830646460170",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/treetester%40treeassistant-tatan.iam.gserviceaccount.com"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions channels/voice/__init__.py
@@ -0,0 +1,21 @@
class JourneyChannel:
def __init__(self, name__):
self.name = name__
self._sessions = dict()

def start(self):
pass

def send_message(self, originator_id, message):
print("Received message: " + message)
pass

def process_message(self, func):
def wrapper():

func(session, message)
print("after")
return wrapper

def get_session(self, dialogue_id):
return self._sessions[dialogue_id]
Empty file added channels/voice/main.py
Empty file.
25 changes: 25 additions & 0 deletions docker-compose-v2.yml
@@ -0,0 +1,25 @@
version: '3.3'

services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- 22181:2181

kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
ports:
- 29092:29092
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1

2 changes: 1 addition & 1 deletion docker-compose.yml
Expand Up @@ -63,7 +63,7 @@ services:
volumes:
- /mnt/wslg/:/mnt/wslg/
journey_speech:
build: ./journey_speech
build: channels/journey_speech
environment:
PULSE_SERVER: /mnt/wslg/PulseServer
GOOGLE_APPLICATION_CREDENTIALS: "google-application-credentials.json"
Expand Down
Empty file.
3 changes: 3 additions & 0 deletions journey_apis/python/kafka_producer.py
@@ -0,0 +1,3 @@
class KafkaProducer:
def __init__(self):
pass
9 changes: 9 additions & 0 deletions journey_apis/python/python-api.iml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.10 (Journey Project)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
9 changes: 9 additions & 0 deletions journey_apis/python/python.iml
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.10 (Journey Project)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file modified journey_central/.gradle/7.3.2/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified journey_central/.gradle/7.3.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 4 additions & 3 deletions journey_central/build.gradle
Expand Up @@ -16,6 +16,9 @@ configurations {

repositories {
mavenCentral()
maven {
url "https://packages.confluent.io/maven/"
}
}

dependencies {
Expand Down Expand Up @@ -49,9 +52,7 @@ dependencies {

// https://mvnrepository.com/artifact/commons-io/commons-io
implementation 'commons-io:commons-io:2.6'

// https://mvnrepository.com/artifact/org.python/jython
implementation 'org.python:jython-standalone:2.7.2'
implementation "org.springframework.kafka:spring-kafka"
}

test {
Expand Down
12 changes: 12 additions & 0 deletions journey_central/google-application-credentials.json
@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "treeassistant-tatan",
"private_key_id": "c17762b3284ad4b2892da86b5acad31d81456480",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCxPkpEu2F/AgfT\nRN1E6d3AWKuUlN6EvWtbMkzJBTVPNE3dHNYwmXv+BdiPr63ZBIruRGngkzmlTWmA\nBnXzxL62ddyUUAGMix0Ei6iI9Dd31YUf8fpxfoesckoTVPVygIVjxaN9a3Bp3vl5\nHffGcMYCJqUjEempno0B4OM+d4NY4Z7giBkUrTJ1OPKWFwJm0EGHVoO+mmMLlnoj\ny4ybKlxzbY67jFRD6x4Ua9q5G3D19h2Xi1GnySIKhwCGRCcl6CIPJr0hJxyBzHS0\ny40QnBPYLL9cM8t8bUuMMvjWyz8On075aEyaUuqSrUE8aLn5vFBSiKHG6f+UFi/8\nW+YwEmxzAgMBAAECggEAB+t3a7ICKnSvkm2MHZCXPtY3d7PEBaMyvg51ukqOfHPv\n240QUERrcyK7vIZMrfSZm9ZYWZdg7Tv6SaUAQqlsUPOo3/YU1TzaFq8brSyMb430\nHUTovFPuqAv4HckFqd1VGIVnFF5nbxoH6uhZGMR6DidZgnZ1PgXYDL9wKAU0snuM\nHhr9DlvPeqh7Y6ghU11wTHEobZV5Ys9Kiz4cekWYKRe4/8yaYHOPThCOIMVukS5q\nxekTIkIcciFOSAqQ7g4U+PILf1+9ZxDbtsdLs0s5R37v8o7YpCxvFaZ6zNxAHrbS\noFrLi2hOUb1deFw5H1a2wADDR/UbcHAlgIj+Vl36cQKBgQDlS6slj52OXNHqiWar\nGkBwbVU9eBKOIT6G6TVSZEfVhUCB5eU+A+zofEnHxoeI6os7JcdW5SBzn7p7tJwN\nBgtvSFF0DLUMVGhyLH6VfCCLC9HsmY0b5f8Nf/+KJz3oZIADcLgtwK7cZwROGTVF\n9I5SxSq/5Y+P9CT82O9Bf7XQ1wKBgQDF4rW4eyjMDsE1orVKXr+K3ItAcOKg5LCC\np83iwtrmt6LiSRTe6JQsSmlkRZhV0z4zFjKqoyYem6u3yhCAUPk2V00vx2hy9gxz\nuGXtY0WZRnGZ4HG+mscORi5JpHr28WjJCSQDUA4jCtpJ4cSUizDikHOXDlKw4TGL\nweP7gAshxQKBgQCyrRVPrqrq7b+SEMHVYR6HvVroDHIBGTy9KmsnqgckBrMuxfOu\nMKbivz9LEpQ5B/O5AoZkWyW/k99gWGwl5ejxLZxzXxeR5RCCr9NwLwq471wFD96a\nt83ZOj3p7Qxb1DzA8YxD8tsP2qLLLO+LdLeXHhdi88K8PVa5RV6jXp5SfwKBgQCs\nQ/wmKTEO0xlnc8mWgH0GiY+//YWMwwjV9PbKnQ6rItntW+mLU7UKCY1N+TfwHwFa\nv8xDt9uLccE/MezDh7orkDxlh5Zp3cBhTPmOeokwMZ7bcgQTBfKbfoT1Hvbc2rN5\nrzdmmt5zqxL0llHnbnSUB2RY7+MUkDXtkFDDtGf8cQKBgQCAescmKqvwC+rXJb1c\nU+HOS9DJMzQzjI54MZqgfjcN68C1zm8Y6TZ9lBGkkGHOoRVolCY5QLTrgeFzCoTC\ns+uhss9CEewRJs8OxxfnAr373JG8ZiGIrw4PHFG3hlPiCCNKoOarEhWT09EAOPY0\ng/LjdJToLWRghp3sFC4v6FUKTA==\n-----END PRIVATE KEY-----\n",
"client_email": "treetester@treeassistant-tatan.iam.gserviceaccount.com",
"client_id": "109961751830646460170",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/treetester%40treeassistant-tatan.iam.gserviceaccount.com"
}
@@ -0,0 +1,20 @@
package com.journey.central.journey.service;

import org.apache.kafka.clients.producer.Producer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class KafkaConsumer {
private final Logger logger = LoggerFactory.getLogger(Producer.class);


@KafkaListener(topics = "users", groupId = "group_id")
public void consume(String message) throws IOException {
logger.info(String.format("#### -> Consumed message -> %s", message));
}
}
@@ -0,0 +1,27 @@
package com.journey.central.journey.service;

import org.apache.kafka.clients.producer.Producer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class KafkaProducer {

private static final Logger logger = LoggerFactory.getLogger(Producer.class);
private static final String TOPIC = "users";

@Autowired
private KafkaTemplate<String, String> kafkaTemplate;

public void sendMessage(String message) {
logger.info(String.format("#### -> Producing message -> %s", message));
this.kafkaTemplate.send(TOPIC, message);
}
}
10 changes: 9 additions & 1 deletion journey_central/src/main/resources/application.properties
Expand Up @@ -5,4 +5,12 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql= true
spring.jpa.show-sql= true
spring.kafka.consumer.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=group_id
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.bootstrap-servers=localhost:9092
31 changes: 0 additions & 31 deletions journey_integrations_executer/Dockerfile

This file was deleted.

77 changes: 0 additions & 77 deletions journey_integrations_executer/app.py

This file was deleted.

2 changes: 0 additions & 2 deletions journey_integrations_executer/entrypoint.sh

This file was deleted.

0 comments on commit 0eb0a3c

Please sign in to comment.