【问题标题】:How to send attachment in chatterbot如何在聊天机器人中发送附件
【发布时间】:2017-08-24 10:54:01
【问题描述】:

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

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

请帮助解决这个问题。

任何帮助将不胜感激。 提前谢谢你。

bot chatting image

【问题讨论】:

    标签: python bots chatterbot


    【解决方案1】:

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

    目前 chatterbot 不支持 Django 上的此功能。但是,您可以在 url、视图和 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>
    }
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-03
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      相关资源
      最近更新 更多