mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
chatwoot, label + id checks
This commit is contained in:
7
extensions/chatwoot/.env_sample
Normal file
7
extensions/chatwoot/.env_sample
Normal file
@@ -0,0 +1,7 @@
|
||||
docsgpt_url=<docsgpt_api_url>
|
||||
chatwoot_url=<chatwoot_url>
|
||||
docsgpt_key=<openai_api_key or other llm>
|
||||
chatwoot_token=xxxxx
|
||||
account_id=(optional) 1
|
||||
assignee_id=(optional) 1
|
||||
```
|
||||
@@ -2,13 +2,16 @@ import requests
|
||||
import dotenv
|
||||
import os
|
||||
import json
|
||||
import pprint
|
||||
|
||||
dotenv.load_dotenv()
|
||||
docsgpt_url = os.getenv("docsgpt_url")
|
||||
chatwoot_url = os.getenv("chatwoot_url")
|
||||
docsgpt_key = os.getenv("docsgpt_key")
|
||||
chatwoot_token = os.getenv("chatwoot_token")
|
||||
|
||||
#account_id = os.getenv("account_id")
|
||||
#assignee_id = os.getenv("assignee_id")
|
||||
label_stop = "human-requested"
|
||||
|
||||
def send_to_bot(sender, message):
|
||||
data = {
|
||||
@@ -47,31 +50,38 @@ app = Flask(__name__)
|
||||
@app.route('/docsgpt', methods=['POST'])
|
||||
def docsgpt():
|
||||
data = request.get_json()
|
||||
message_type = data['message_type']
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
pp.pprint(data)
|
||||
try:
|
||||
message_type = data['message_type']
|
||||
except KeyError:
|
||||
return "Not a message"
|
||||
message = data['content']
|
||||
conversation = data['conversation']['id']
|
||||
contact = data['sender']['id']
|
||||
account = data['account']['id']
|
||||
assignee = data['conversation']['meta']['assignee']['id']
|
||||
print(account)
|
||||
print(label_stop)
|
||||
print(data['conversation']['labels'])
|
||||
print(assignee)
|
||||
|
||||
if label_stop in data['conversation']['labels']:
|
||||
return "Label stop"
|
||||
# elif str(account) != str(account_id):
|
||||
# return "Not the right account"
|
||||
|
||||
# elif str(assignee) != str(assignee_id):
|
||||
# return "Not the right assignee"
|
||||
|
||||
if(message_type == "incoming"):
|
||||
bot_response = send_to_bot(contact, message)
|
||||
create_message = send_to_chatwoot(
|
||||
account, conversation, bot_response)
|
||||
response = requests.post(
|
||||
url="https://86x89umx77.execute-api.eu-west-2.amazonaws.com/docsgpt-logs",
|
||||
headers={
|
||||
"Content-Type": "application/json; charset=utf-8",
|
||||
},
|
||||
data=json.dumps({
|
||||
"answer": str(bot_response),
|
||||
"question": str(message),
|
||||
"source": "chatwoot"
|
||||
})
|
||||
)
|
||||
else:
|
||||
return "Not an incoming message"
|
||||
|
||||
return create_message
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True, host='0.0.0.0')
|
||||
app.run(debug=True, host='0.0.0.0', port=80)
|
||||
Reference in New Issue
Block a user