Skip to content

Commit

Permalink
modify chatbot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Haebuk committed Jul 19, 2021
1 parent f95e0ee commit a9bea6c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 154 deletions.
45 changes: 6 additions & 39 deletions project/flask/api/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,6 @@ class ChatbotMessageSender:
# chatbot custom secret key
secret_key = 'S2V4elFrenVqbGNXQURQWnFKc2V2ZWJjZHJWdXdWc0c='

def welcome(self):
timestamp = self.get_timestamp()
request_body = {
"version": "v2",
"userId": "U47b00b58c90f8e47428af8b7bddcda3d",
"timestamp": timestamp,
"bubbles": [
{
"type": "text",
}
],
"event": "open"
}

## Request body
encode_request_body = json.dumps(request_body).encode('UTF-8')

## make signature
signature = self.make_signature(self.secret_key, encode_request_body)

## headers
custom_headers = {
'Content-Type': 'application/json;UTF-8',
'X-NCP-CHATBOT_SIGNATURE': signature
}

# print("## Timestamp : ", timestamp)
# print("## Signature : ", signature)
# print("## headers ", custom_headers)
print("## Request Body : ", encode_request_body)

## POST Request
response = requests.post(headers=custom_headers, url=self.ep_path, data=encode_request_body)

return response

def req_message_send(self):

timestamp = self.get_timestamp()
Expand All @@ -59,7 +23,7 @@ def req_message_send(self):
{
'type': 'text',
'data': {
'description': 'About Me'
'description': '도서 추천해줘'
}
}
],
Expand Down Expand Up @@ -87,7 +51,8 @@ def req_message_send(self):
response = requests.post(headers=custom_headers, url=self.ep_path, data=encode_request_body)

return response
def success():

def success(self):
timestamp = self.get_timestamp()
request_body = {
"version": "v2",
Expand Down Expand Up @@ -130,6 +95,8 @@ def success():

## POST Request
response = requests.post(headers=custom_headers, url=self.ep_path, data=encode_request_body)

return response
@staticmethod
def get_timestamp():
timestamp = datetime.now()
Expand All @@ -147,7 +114,7 @@ def make_signature(secret_key, request_body):

if __name__ == '__main__':

res = ChatbotMessageSender().welcome()
res = ChatbotMessageSender().req_message_send()

print(res.status_code)
if(res.status_code == 200):
Expand Down
78 changes: 0 additions & 78 deletions project/flask/api/dd.py

This file was deleted.

37 changes: 0 additions & 37 deletions project/flask/dialogflow.py

This file was deleted.

0 comments on commit a9bea6c

Please sign in to comment.