Я пытаюсь сделать запрос webhook из диалогового потока в мой API остальных, который работает в python flask и ngrok. Но это не работает. При проверке информации о диагностике c она показывает, что вызов Webhook не выполнен: РАЗРЕШЕНИЕ НА РАЗРЕШЕНИЕ.
Адрес API http://4cf46e81.ngrok.io/webhook
Информация о диагностике c приведены ниже.
{
"responseId": "ad38813a-ba56-4eba-bc45-306b783346bc-e1f57fd1",
"queryResult": {
"queryText": "placement statistics 2019",
"action": "placementyear",
"parameters": {
"year": "2019"
},
"allRequiredParamsPresent": true,
"intent": {
"name": "projects/cecb-yfoing/agent/intents/16c7b34c-b7e4-470c-8b6f-8ae7920a330f",
"displayName": "placement statistics"
},
"intentDetectionConfidence": 0.68428475,
"diagnosticInfo": {
"webhook_latency_ms": 14
},
"languageCode": "en"
},
"webhookStatus": {
"code": 7,
"message": "Webhook call failed. Error: PERMISSION_DENIED."
}
}
Код API приведен ниже.
# /index.py
from flask import Flask, request, jsonify, render_template
import os
import dialogflow
import requests
import json
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
# run Flask app
if __name__ == "__main__":
app.run()
@app.route('/webhook', methods=['GET','POST'])
def webhook():
data = request.get_json(silent=True,force=True)
#result = data.get("queryResult")
#parameters = result.get("parameters")
year=data['queryResult']['parameters']['year']
#year = parameters.get("year")
if year == '2019':
reply = {
"fulfillmentText": "CTS 75 CTS 170",
}
return jsonify(reply)
else:
reply = {
"fulfillmentText": "Ok. Booking cancelled.",
}
return jsonify(reply)
def detect_intent_texts(project_id, session_id, text, language_code):
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)
if text:
text_input = dialogflow.types.TextInput(
text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response = session_client.detect_intent(
session=session, query_input=query_input)
return response.query_result.fulfillment_text
@app.route('/send_message', methods=['POST'])
def send_message():
message = request.form['message']
project_id = os.getenv('DIALOGFLOW_PROJECT_ID')
fulfillment_text = detect_intent_texts(project_id, "unique", message, 'en')
response_text = { "message": fulfillment_text }
return jsonify(response_text)