Skip to content

Alfex4936/kakaoChatbot-Ajou

Repository files navigation

카카오톡 챗봇 FastAPI 서버

TODO - Kafka 서버를 통한 자동 전달

TODO - 각 유저마다 last notice index

@현재 서버 Go언어 Gin으로 변경됨 | @아주대 공지 챗봇

block1 / block2

AWS RDS (MySQL 모델)

사용

AWS EC2 + S3 + RDS

ubuntu:~$ virtualenv server
ubuntu:~$ source ~/server/bin/activate

(server) ubuntu:~$ pip install fastapi uvicorn SQLAlchemy

(server) ubuntu:~$ aws s3 cp s3://bucket/kakao.py .
(server) ubuntu:~$ aws s3 cp s3://bucket/parser.py .

(server) ubuntu:~$ python parser.py
(server) ubuntu:~$ python kakao.py
INFO:     Started server process [id]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)

특징

카카오 챗봇

title, items, text... 길이를 넘기면 제대로 출력이 안될 수도 있다.

simpleText: text(1000)

ListCard: header(15), list_title(35), list_description(16), lists(5)

Carousel: items(10)

카카오 챗봇 API JSON Model

class KakaoUser(BaseModel):
    id: str
    properties: Dict
    type: str


class KakaoUserRequest(BaseModel):
    block: Dict
    lang: Optional[str]
    params: Dict
    timezone: str
    user: KakaoUser
    utterance: str


class KakaoAction(BaseModel):
    clientExtra: Optional[Dict]
    detailParams: Dict
    id: str
    name: str
    params: Dict


class KakaoAPI(BaseModel):
    """Main Kakao JSON"""

    action: KakaoAction
    bot: Dict
    contexts: Optional[List]
    intent: Dict
    userRequest: KakaoUserRequest

@application.post("/route", response_model=KakaoAPI)
async def message(content: KakaoAPI):
    ...

예제 JSON 반응

"2021 검색"

INFO: server - "POST /search HTTP/1.1" 200 OK

{
    "action": {
        "clientExtra": {},
        "detailParams": {
            "sys_text": {
                "groupName": "",
                "origin": "2021",
                "value": "2021"
            }
        },
        "id": "id",
        "name": "스킬 이름",
        "params": {
            "sys_text": "2021"
        }
    },
    "bot": {
        "id": "id",
        "name": "AjouNotice"
    },
    "contexts": [],
    "intent": {
        "extra": {
            "reason": {
                "code": 1,
                "message": "OK"
            }
        },
        "id": "id",
        "name": "공지 키워드 검색"
    },
    "userRequest": {
        "block": {
            "id": "id",
            "name": "공지 키워드 검색"
        },
        "lang": "kr",
        "params": {
            "ignoreMe": "true",
            "surface": "BuilderBotTest"
        },
        "timezone": "Asia/Seoul",
        "user": {
            "id": "id",
            "properties": {
                "botUserKey": "key",
                "bot_user_key": "key"
            },
            "type": "botUserKey"
        },
        "utterance": "2021 검색\n"
    }
}

POST = /message | 발화 = "어제 공지 알려줘", "오늘 공지 알려줘"...

entity = "when"

POST = /today2

"오늘" 공지에서 더보기를 누르면 10개 정도의 공지를 더 불러옵니다.

(5개 이하일 시 아주대 홈피로 이동됨)

POST = /last | 발화 = "지난 공지 알려줘", "마지막 공지"...

entity =

POST = /ask | 발화 = "카테고리", "분류"...

POST = /search | 발화 = "카테고리", "분류"...

entity = 분류 필요

POST = /schedule | 발화 = "달력", "일정" ...

entity = 분류 필요

TO-DO: Selenium을 통한 자동 db 업데이트

(수원 영통구 날씨를 weather.naver.com에서 불러옴)

POST = /info/weather2 | 발화 = "날씨", "아주대 날씨", "날씨 좋아?" ...

POST = /info/prof | 발화 = "인물"

"인물" 입력 후 키워드 검색

TO-DO: 더 나은 발화문

POST = /info/library | 발화 = "도서관", "좌석"

발화문 입력 시 중앙도서관 좌석 이용 현황을 불러옵니다.

TO-DO: 더 나은 메시지 포맷

POST = /info/meal | 발화 = "오늘 학식", "내일 학생", "내일 교직원", "내일 기숙사" ...

오늘/내일 장소를 입력하면 시간에 맞는 장소의 학식 정보를 불러옵니다.

TO-DO: 더 나은 메시지 포맷

About

Python언어 FastAPI 웹 프레임워크를 이용한 아주대학교 카카오 챗봇 (learning objectives)

Topics

Resources

License

Stars

Watchers

Forks

Languages