0

我正在尝试使用 python 构建一个机器人。我正在使用chatterbot(一个python包),我能够根据我建立的知识发送和接收消息。

但我想在聊天回复中发送附件。附件可以是excel文件或图像的pdf。我也尝试过为消息响应和 listTrainer 制作自定义类。

请帮助解决这个问题。

任何帮助将不胜感激。先感谢您。

聊天机器人图片

4

1 回答 1

0

我认为您正在使用django_chatterbot应用程序。

目前,chatterbot 不支持 Django 上的此功能。但是,您可以在 url、views 和 app.html 文件中进行工作以完成此任务。

url.py

from django.conf.urls import url
from .views import ChatterBotView


urlpatterns = [
    url(
        r'^$',
        ChatterBotView.as_view(),
        name='chatterbot',
    ),
    url(r'^test/getFile', 'getFile')
]

views.py

def getFile(request):
    fileContent = "Your name is %s" % request.GET['name']
    res = HttpResponse(fileContent)
    res['Content-Disposition'] = 'attachment; filename=yourname.txt'
    return res

app.html 中

if (inputData.text.indexOf("please download this script and run it") !=-1) {
    <script type="text/javascript">
        var data = {name: 'Jon'};
        $(function(){
            $("body").append('<iframe src="/test/getFile?'+ $.param(data) + '" style="display: none;" ></iframe>');
        });
    </script>
}

我希望这些信息能帮助您解决问题。

于 2017-08-24T02:54:01.947 回答