首页 > 解决方案 > Django/Dialogflow 聊天机器人,在我的笔记本电脑上工作。当我部署到服务器时,我必须在匹配意图之前重复相同的句子

问题描述

我有一个开发设置(笔记本电脑、Django、Dialogflow、Ngrok)当我测试我的聊天机器人时一切都很好。

我有一个生产设置(由 Digital Ocean、Django、Dialogflow、Nginx、gunicorn 托管的 Ubuntu 服务器)当我测试对话流时有问题匹配意图。即我必须重复同一句话几次,直到它符合意图。

任何想法为什么会这样?

我已经尝试将 dialogflow fullfillment 指向我的开发环境并从生产环境中点击它,但是我仍然必须重复自己以获得匹配的意图。

我已经尝试将对话流指向生产环境并从开发服务器上点击它,并且一切正常。

在生产服务器上测试的对话:

您好,来自 Cemlyn 集团的 Chris!我能为你做什么?也许与地图有关?返回地图 对不起,我不明白你想要什么。返回地图 对不起,我不明白你想要什么。返回地图 Chris 你想返回什么地图?1 对不起,我不明白你想要什么。1 对不起,我不明白你想要什么。1 OK 只是确认一下,你要我返回 1 给你 Chris 返回地图 Chris 你要返回什么地图?1 对不起,我不明白你想要什么。1 对不起,我不明白你想要什么。1 OK 只是为了确认,你要我为你返回 1 克里斯

从开发设置中测试的对话:

您好,来自 Cemlyn 集团的 Chris!我能为你做什么?也许与地图有关?返回地图 Chris 你想返回什么地图?1 OK 只是为了确认,你要我为你返回 1 克里斯

网络钩子看起来像这样:

def webhook(request):
    # build a request object
    req = json.loads(request.body)
    #s = Session.objects.get(pk='')
    #print(s)
    # get action from json
    action = req.get('queryResult').get('action')
    params = req.get('queryResult').get('parameters')
    print('session hitting webhook - '*3)
    print(request.session.session_key)
    for key, value in request.session.items():
        print('{} => {}'.format(key, value))
    print(req)    

    if action == 'issue_a_map':
        if 'Maps' in params:

            if params['Maps']:

                mapid = int((params['Maps'][0]))
                group = (params['ValleyGroups'][0])

                if mapid == 99:
                    fulfillmentText = {'fulfillmentText': 'issue the next map for ' + group + ' from webhook.'}            
                else:

                    fulfillmentText = {'fulfillmentText': 'issue a map from webhook.'}

    elif action == 'return_a_map':
        print('return a map - '*4)
        if 'Maps' in params:
            if params['Maps']:           
                mapid = int(params['Maps'])
                map = CongMap.objects.get(map_no=mapid)
                if map.issued:
                    retuner = params['username']
                    return_map_form(request, mapid, retuner ) 
                    fulfillmentText = {'fulfillmentText': 'OK I will return map ' + str(mapid) + ' for you ' +params['username']}
                else:
                    #reply = prepresponse('name please','admin','welcome_event')
                    fulfillmentText = {'fulfillmentText': 'Hmmm there is a problem, that map isnt issued currently. A map has to be issued before it can be returned.'}
                    ffr=fulfillment_response()
                    fftext= ffr.fulfillment_text(fulfillmentText)
                    params = {'problem': str(map.map_title) +' map hasnt been issued however we are trying to return it.'}
                    fue = ffr.followup_event_input('ProblemEvent', params)        
                    ffm = None
                    ocx = None
                    reply = ffr.main_response(fftext, ffm, ocx, fue)

                    return JsonResponse(reply, safe=False)

            else:
                fulfillmentText = {'fulfillmentText': 'Sorry I need to know the map no or name.'}       
        else:
            fulfillmentText = {'fulfillmentText': 'Sorry I need to know the map no or name.'}

    elif action == 'help_problem':
        fulfillmentText = {'fulfillmentText': 'OK ' +params['username'] +', I will send him an email asking him to help.'}
        send_mail('Territory Problem', '{}. Please can you help {} with this problem'.format(params['problem'], params['username']), 'territorybot@chivers.io', ['tain259@gmail.com'])
    else:
        fulfillmentText = {'fulfillmentText': 'Sorry, I dont understand what you want.'}
    # return response

    return JsonResponse(fulfillmentText, safe=False)

标签: dialogflow-es

解决方案


推荐阅读