403 IAM permission 'dialogflow.sessions.detectIntent' on 'projects/None/agent' denied. with flask

十年热恋 提交于 2020-04-17 22:51:47

问题


in /send_message
fulfillment_text = detect_intent_texts(project_id,, message, 'en') what should be passed as 2nd argument.

# /index.py
from flask import Flask, request, jsonify, render_template
import os
import dialogflow
import requests
import json
import pusher
import tryy

pusher_client = pusher.Pusher(
        app_id=os.getenv('PUSHER_APP_ID'),
        key=os.getenv('PUSHER_KEY'),
        secret=os.getenv('PUSHER_SECRET'),
        cluster=os.getenv('PUSHER_CLUSTER'),
        ssl=True)

final = []
app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')

@app.route('/webhook', methods=['POST'])
def static_reply():
    string = "Hello there, this reply is from the webhook !! "
    my_result =  {"fulfillmentText": string, "source": string}
    return jsonify(my_result)
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():
    try:
        socketId = request.form['socketId']
    except KeyError:
        socketId = ''

    message = request.form['message']
    project_id = os.getenv('DIALOGFLOW_PROJECT_ID')
    fulfillment_text = detect_intent_texts(project_id,, message, 'en')
    response_text = { "message":  fulfillment_text }

    pusher_client.trigger(
        'Virtual-Police', 
        'new_message', 
        {
            'human_message': message, 
            'bot_message': fulfillment_text,
        },
        socketId
    )

    return jsonify(response_text)
# run Flask app
if __name__ == "__main__":
    app.run()

来源:https://stackoverflow.com/questions/60758268/403-iam-permission-dialogflow-sessions-detectintent-on-projects-none-agent-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!