chatwoot 开源客服系统搭建

打印 上一主题 下一主题

主题 855|帖子 855|积分 2565

1. 准备开源客服系统(我是用的Chatwoot )

可以选择以下开源客服系统作为底子:


  • Chatwoot: 开源,多语言,跟踪和分析,支持多渠道客户对接,自动化和工作流等。源码
  • Zammad: 当代的开源工单系统。
  • FreeScout: 免费且轻量化的 Help Desk 系统。
Chatwoot 移动应用项目常见问题解决方案。


2. 创建 Docker 配置文件



  • 创建chatwoot目次
  
  1. mkdir chatwoot
  2. cd chatwoot
  3. # 新建docker挂载的子目录
  4. mkdir -p ./{postgres,redis,storage}
  5. # 给chatwoot目录授权
  6. chmod -R 777 chatwoot
复制代码


  • 在chatwoot目次下创建一个 docker-compose.yml 文件来定义服务:
  
  1. version: '3'
  2. services:
  3.   base: &base
  4.     image: chatwoot/chatwoot:latest
  5.     #container_name: chatwoot-base
  6.     env_file: env.txt ## Change this file for customized env variables
  7.     volumes:
  8.       - ./storage:/app/storage
  9.   rails:
  10.     <<: *base
  11.     depends_on:
  12.       - postgres
  13.       - redis
  14.     ports:
  15.       - 3000:3000
  16.     environment:
  17.       - NODE_ENV=production
  18.       - RAILS_ENV=production
  19.       - INSTALLATION_ENV=docker
  20.     entrypoint: docker/entrypoints/rails.sh
  21.     command: ['bundle', 'exec', 'rails', 's', '-p', '3000', '-b', '0.0.0.0']
  22.   sidekiq:
  23.     <<: *base
  24.     depends_on:
  25.       - postgres
  26.       - redis
  27.     environment:
  28.       - NODE_ENV=production
  29.       - RAILS_ENV=production
  30.       - INSTALLATION_ENV=docker
  31.     command: ['bundle', 'exec', 'sidekiq', '-C', 'config/sidekiq.yml']
  32.   postgres:
  33.     image: postgres:14
  34.     container_name: chatwoot-postgres
  35.     restart: always
  36.     #ports:
  37.     #  - 5432:5432
  38.     volumes:
  39.       - ./postgres:/var/lib/postgresql/data
  40.     environment:
  41.       - POSTGRES_DB=chatwoot
  42.       - POSTGRES_USER=postgres
  43.       # Please provide your own password.
  44.       - POSTGRES_PASSWORD=数据库密码
  45.   redis:
  46.     image: redis:6.2-alpine
  47.     container_name: chatwoot-redis
  48.     restart: always
  49.     command: ["sh", "-c", "redis-server --requirepass "$REDIS_PASSWORD""]
  50.     env_file: env.txt
  51.     volumes:
  52.       - ./redis:/data
  53.     #ports:
  54.     #  - 6379:6379
  55. #  middleware:
  56. #    build: ./middleware
  57. #    restart: always
  58. #    ports:
  59. #      - "4000:4000"
  60. #    environment:
  61. #      - CHATWOOT_BOT_TOKEN=你的CHATWOOT机器人token
  62. #      - CHATWOOT_URL=http://CHATWOOT的ip:3000
  63. #      - RASA_URL=http://RASA的ip:5005
复制代码


  • 在chatwoot目次下创建一个 env.txt文件来定义服务配置:
  
  1. # Learn about the various environment variables at
  2. # https://www.chatwoot.com/docs/self-hosted/configuration/environment-variables/#rails-production-variables
  3. # Used to verify the integrity of signed cookies. so ensure a secure value is set
  4. # SECRET_KEY_BASE should be alphanumeric. Avoid special characters or symbols.
  5. # Use `rake secret` to generate this variable
  6. # 用于验证签名cookie的完整性。因此,请确保设置了一个安全值!
  7. SECRET_KEY_BASE=6eONF6WVhCjbsPMOawORdTF0MccxXgheFvklSzH5ud0=
  8. # Replace with the URL you are planning to use for your app
  9. # 替换你运行的域名或者IP地址
  10. FRONTEND_URL=https://你的ip:3000
  11. # To use a dedicated URL for help center pages
  12. # HELPCENTER_URL=http://0.0.0.0:3000
  13. # If the variable is set, all non-authenticated pages would fallback to the default locale.
  14. # Whenever a new account is created, the default language will be DEFAULT_LOCALE instead of en
  15. # DEFAULT_LOCALE=en
  16. # If you plan to use CDN for your assets, set Asset CDN Host
  17. ASSET_CDN_HOST=
  18. # Force all access to the app over SSL, default is set to false
  19. FORCE_SSL=false
  20. # This lets you control new sign ups on your chatwoot installation
  21. # true : default option, allows sign ups
  22. # false : disables all the end points related to sign ups
  23. # api_only: disables the UI for signup, but you can create sign ups via the account apis
  24. # 注册选项
  25. # true : 允许注册
  26. # false : 关闭注册
  27. # api_only: 关闭UI上的注册,但可以通过API注册
  28. ENABLE_ACCOUNT_SIGNUP=false
  29. # Redis config
  30. # Redis 配置
  31. # specify the configs via single URL or individual variables
  32. # ref: https://www.iana.org/assignments/uri-schemes/prov/redis
  33. # You can also use the following format for the URL: redis://:password@host:port/db_number
  34. REDIS_URL=redis://redis:6379
  35. # If you are using docker-compose, set this variable's value to be any string,
  36. # which will be the password for the redis service running inside the docker-compose
  37. # to make it secure
  38. # 设置REDIS的密码,建议复杂一点
  39. REDIS_PASSWORD=
  40. # Redis Sentinel can be used by passing list of sentinel host and ports e,g. sentinel_host1:port1,sentinel_host2:port2
  41. REDIS_SENTINELS=
  42. # Redis sentinel master name is required when using sentinel, default value is "mymaster".
  43. # You can find list of master using "SENTINEL masters" command
  44. REDIS_SENTINEL_MASTER_NAME=
  45. # By default Chatwoot will pass REDIS_PASSWORD as the password value for sentinels
  46. # Use the following environment variable to customize passwords for sentinels.
  47. # Use empty string if sentinels are configured with out passwords
  48. # REDIS_SENTINEL_PASSWORD=
  49. # Redis premium breakage in heroku fix
  50. # enable the following configuration
  51. # ref: https://github.com/chatwoot/chatwoot/issues/2420
  52. # REDIS_OPENSSL_VERIFY_MODE=none
  53. # Postgres Database config variables
  54. # Postgres Database 配置,密码复杂一点
  55. # You can leave POSTGRES_DATABASE blank. The default name of
  56. # the database in the production environment is chatwoot_production
  57. # POSTGRES_DATABASE=
  58. POSTGRES_HOST=postgres
  59. POSTGRES_USERNAME=postgres
  60. POSTGRES_PASSWORD=postgres
  61. RAILS_ENV=development
  62. # Changes the Postgres query timeout limit. The default is 14 seconds. Modify only when required.
  63. # POSTGRES_STATEMENT_TIMEOUT=14s
  64. RAILS_MAX_THREADS=5
  65. # The email from which all outgoing emails are sent
  66. # 下面时SMTP配置,可以用来配置邮件通知。具体配置信息建议到你的邮箱服务商那里查看。
  67. # could user either  `email@yourdomain.com` or `BrandName <email@yourdomain.com>`
  68. MAILER_SENDER_EMAIL=Chatwoot <chatwoot@qq.com>
  69. SMTP_DOMAIN=qq.com
  70. # Set the value to "mailhog" if using docker-compose for development environments,
  71. # Set the value as "localhost" or your SMTP address in other environments
  72. # If SMTP_ADDRESS is empty, Chatwoot would try to use sendmail(postfix)
  73. SMTP_ADDRESS=
  74. SMTP_PORT=
  75. SMTP_USERNAME=
  76. SMTP_PASSWORD=
  77. # plain,login,cram_md5
  78. SMTP_AUTHENTICATION=login
  79. SMTP_ENABLE_STARTTLS_AUTO=true
  80. SMTP_DEBUG_OUTPUT=true
  81. # Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert', see http://api.rubyonrails.org/classes/ActionMailer/Base.html
  82. SMTP_OPENSSL_VERIFY_MODE=none
  83. RAILS_MAILER_TIMEOUT=60
  84. # Comment out the following environment variables if required by your SMTP server
  85. # 如果您的SMTP服务器需要,请注释掉以下环境变量。
  86. #SMTP_TLS=false
  87. #SMTP_SSL=false
  88. # SMTP_OPEN_TIMEOUT
  89. # SMTP_READ_TIMEOUT
  90. # Mail Incoming
  91. # 下面是连续会话使用的邮箱
  92. # This is the domain set for the reply emails when conversation continuity is enabled
  93. MAILER_INBOUND_EMAIL_DOMAIN=
  94. # Set this to the appropriate ingress channel with regards to incoming emails
  95. # 将此设置为适当的接收渠道,以接收到电子邮件
  96. # 支持的邮箱 :
  97. # Possible values are :
  98. # relay for Exim, Postfix, Qmail
  99. # mailgun for Mailgun
  100. # mandrill for Mandrill
  101. # postmark for Postmark
  102. # sendgrid for Sendgrid
  103. RAILS_INBOUND_EMAIL_SERVICE=
  104. # Use one of the following based on the email ingress service
  105. # Ref: https://edgeguides.rubyonrails.org/action_mailbox_basics.html
  106. # Set this to a password of your choice and use it in the Inbound webhook
  107. # 根据电子邮件入口服务,使用以下其中一个
  108. # 参考: https://edgeguides.rubyonrails.org/action_mailbox_basics.html
  109. # 将其设置为您选择的密码,并在入站webhook中使用它
  110. RAILS_INBOUND_EMAIL_PASSWORD=
  111. MAILGUN_INGRESS_SIGNING_KEY=
  112. MANDRILL_INGRESS_API_KEY=
  113. # Creating Your Inbound Webhook Instructions for Postmark and Sendgrid:
  114. # Inbound webhook URL format:
  115. #    https://actionmailbox:[YOUR_RAILS_INBOUND_EMAIL_PASSWORD]@[YOUR_CHATWOOT_DOMAIN.COM]/rails/action_mailbox/[RAILS_INBOUND_EMAIL_SERVICE]/inbound_emails
  116. # Note: Replace the values inside the brackets; do not include the brackets themselves.
  117. # Example: https://actionmailbox:mYRandomPassword3@chatwoot.example.com/rails/action_mailbox/postmark/inbound_emails
  118. # For Postmark
  119. # Ensure the 'Include raw email content in JSON payload' checkbox is selected in the inbound webhook section.
  120. # Storage
  121. # 存储信息的形式,默认本地
  122. ACTIVE_STORAGE_SERVICE=local
  123. # Amazon S3
  124. # documentation(参考文档): https://www.chatwoot.com/docs/configuring-s3-bucket-as-cloud-storage
  125. S3_BUCKET_NAME=
  126. AWS_ACCESS_KEY_ID=
  127. AWS_SECRET_ACCESS_KEY=
  128. AWS_REGION=
  129. # Log settings(日志设置)
  130. # Disable if you want to write logs to a file
  131. RAILS_LOG_TO_STDOUT=true
  132. LOG_LEVEL=info
  133. LOG_SIZE=500
  134. # Configure this environment variable if you want to use lograge instead of rails logger
  135. #LOGRAGE_ENABLED=true
  136. ### This environment variables are only required if you are setting up social media channels
  137. # Facebook
  138. # documentation: https://www.chatwoot.com/docs/facebook-setup
  139. FB_VERIFY_TOKEN=
  140. FB_APP_SECRET=
  141. FB_APP_ID=
  142. # https://developers.facebook.com/docs/messenger-platform/instagram/get-started#app-dashboard
  143. IG_VERIFY_TOKEN=
  144. # Twitter
  145. # documentation: https://www.chatwoot.com/docs/twitter-app-setup
  146. TWITTER_APP_ID=
  147. TWITTER_CONSUMER_KEY=
  148. TWITTER_CONSUMER_SECRET=
  149. TWITTER_ENVIRONMENT=
  150. #slack integration
  151. SLACK_CLIENT_ID=
  152. SLACK_CLIENT_SECRET=
  153. # Google OAuth
  154. GOOGLE_OAUTH_CLIENT_ID=
  155. GOOGLE_OAUTH_CLIENT_SECRET=
  156. GOOGLE_OAUTH_CALLBACK_URL=
  157. ### Change this env variable only if you are using a custom build mobile app
  158. ## Mobile app env variables
  159. IOS_APP_ID=L7YLMN4634.com.chatwoot.app
  160. ANDROID_BUNDLE_ID=com.chatwoot.app
  161. # https://developers.google.com/android/guides/client-auth (use keytool to print the fingerprint in the first section)
  162. ANDROID_SHA256_CERT_FINGERPRINT=AC:73:8E:DE:EB:56:EA:CC:10:87:02:A7:65:37:7B:38:D4:5D:D4:53:F8:3B:FB:D3:C6:28:64:1D:AA:08:1E:D8
  163. ### Smart App Banner
  164. # https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html
  165. # You can find your app-id in https://itunesconnect.apple.com
  166. #IOS_APP_IDENTIFIER=1495796682
  167. ## Push Notification
  168. ## generate a new key value here : https://d3v.one/vapid-key-generator/
  169. # VAPID_PUBLIC_KEY=
  170. # VAPID_PRIVATE_KEY=
  171. #
  172. # for mobile apps
  173. # FCM_SERVER_KEY=
  174. ### APM and Error Monitoring configurations
  175. ## Elastic APM
  176. ## https://www.elastic.co/guide/en/apm/agent/ruby/current/getting-started-rails.html
  177. # ELASTIC_APM_SERVER_URL=
  178. # ELASTIC_APM_SECRET_TOKEN=
  179. ## Sentry
  180. # SENTRY_DSN=
  181. ## Scout
  182. ## https://scoutapm.com/docs/ruby/configuration
  183. # SCOUT_KEY=YOURKEY
  184. # SCOUT_NAME=YOURAPPNAME (Production)
  185. # SCOUT_MONITOR=true
  186. ## NewRelic
  187. # https://docs.newrelic.com/docs/agents/ruby-agent/configuration/ruby-agent-configuration/
  188. # NEW_RELIC_LICENSE_KEY=
  189. # Set this to true to allow newrelic apm to send logs.
  190. # This is turned off by default.
  191. # NEW_RELIC_APPLICATION_LOGGING_ENABLED=
  192. ## Datadog
  193. ## https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#environment-variables
  194. # DD_TRACE_AGENT_URL=
  195. # MaxMindDB API key to download GeoLite2 City database
  196. # IP_LOOKUP_API_KEY=
  197. ## Rack Attack configuration
  198. ## To prevent and throttle abusive requests
  199. # ENABLE_RACK_ATTACK=true
  200. # RACK_ATTACK_LIMIT=300
  201. # ENABLE_RACK_ATTACK_WIDGET_API=true
  202. ## Running chatwoot as an API only server
  203. ## setting this value to true will disable the frontend dashboard endpoints
  204. # CW_API_ONLY_SERVER=false
  205. ## Development Only Config
  206. # if you want to use letter_opener for local emails
  207. # LETTER_OPENER=true
  208. # meant to be used in github codespaces
  209. # WEBPACKER_DEV_SERVER_PUBLIC=
  210. # If you want to use official mobile app,
  211. # the notifications would be relayed via a Chatwoot server
  212. ENABLE_PUSH_RELAY_SERVER=true
  213. # Stripe API key
  214. STRIPE_SECRET_KEY=
  215. STRIPE_WEBHOOK_SECRET=
  216. # Set to true if you want to upload files to cloud storage using the signed url
  217. # Make sure to follow https://edgeguides.rubyonrails.org/active_storage_overview.html#cross-origin-resource-sharing-cors-configuration on the cloud storage after setting this to true.
  218. DIRECT_UPLOADS_ENABLED=
  219. #MS OAUTH creds
  220. AZURE_APP_ID=
  221. AZURE_APP_SECRET=
  222. ## Advanced configurations
  223. ## Change these values to fine tune performance
  224. # control the concurrency setting of sidekiq
  225. # SIDEKIQ_CONCURRENCY=10
  226. # AI powered features
  227. ## OpenAI key
  228. # OPENAI_API_KEY=
  229. # Housekeeping/Performance related configurations
  230. # Set to true if you want to remove stale contact inboxes
  231. # contact_inboxes with no conversation older than 90 days will be removed
  232. # REMOVE_STALE_CONTACT_INBOX_JOB_STATUS=false
复制代码


  • 在env.txt文件中配置好以下参数:
  
  1. SECRET_KEY_BASE=你的系统令牌ley (可以用命令 openssl rand -base64 32 来生成)
  2. FRONTEND_URL=https://你的ip:3000 (前端地址,根据实际情况填写)
  3. HELPCENTER_URL=https://你的ip:3000 (帮助中心地址,可以和FRONTEND_URL一样)
  4. REDIS_URL=redis://password@redis:6379/1 (redis://:password@host:port/db_number)
  5. REDIS_PASSWORD=redis密码
  6. POSTGRES_HOST=postgres
  7. POSTGRES_USERNAME=postgres
  8. POSTGRES_PASSWORD=(数据库密码,需与docker-compose.yaml中的postgres数据库密码保持一致)
复制代码

3. 启动服务

   通过运行迁移来准备数据库

  # `docker compose` 是新版 cli 命令,如果执行不了,就换成 `docker-compose`
# 即 `docker-compose run --rm rails bundle exec rails db:chatwoot_prepare` 
docker compose run --rm rails bundle exec rails db:chatwoot_prepare
 
   
  1. ubuntu@ubuntu:~/chatwoot$ docker compose run --rm rails bundle exec rails db:chatwoot_prepare
  2. [+] Creating 2/2
  3. ✔ Container chatwoot-postgres-1  Recreated                                                                                                                             0.1s
  4. .....
  5. fatal: not a git repository (or any of the parent directories): .git
  6. Created database 'chatwoot_production'
  7. ubuntu@ubuntu:~/chatwoot$
复制代码
   当看到 Created database 'chatwoot_production' 即表示创建乐成,继续执行下面的命令
  
  docker-compose down &&  docker-compose up -d
  
  备注:chatwoot-base-1不会运行,表现的是exit状态,不影响使用。
   使用欣赏器管理背景访问:http://你的ip:3000/     
 注意事项


  • 第一次进来先要初始化账号信息,设置好系统语言
超等管理员背景:http://你的ip:3000/super_admin

设置中文:Settings --> Account Setting --> Site language ,下拉找到简体中文

创建web收件箱,按照步骤正确填写信息后创建

创建收件箱末了一步,生成 script 代码

将生成的js代码放到你的html中

末了效果


4. 扩展功能



  • 对接邮箱功能(在env.txt 文件中配置好以下参数:
  
  1. # 发送者,格式:“好日子 <123456789@qq.com>”  或  123456789@qq.com
  2. MAILER_SENDER_EMAIL=好日子 <123456789@qq.com>
  3. # SMTP 邮件服务器域名(例:qq.com,gmail.com)
  4. SMTP_DOMAIN=cannmax.vip
  5. # SMTP 邮件服务器地址(例:qq邮箱:smtp.qq.com,谷歌:smtp.gmail.com)
  6. SMTP_ADDRESS=
  7. # 587(TLS)或 465(SSL)
  8. SMTP_PORT=
  9. # 邮箱账号
  10. SMTP_USERNAME=
  11. # 邮箱密码或授权码(根据邮箱服务器规则去填,例:qq邮箱为邮箱授权码,)
  12. SMTP_PASSWORD=
  13. # 邮箱服务器SMTP 认证方式,通常为 plain,参数有plain,login,cram_md5
  14. SMTP_AUTHENTICATION=login
  15. # 是否使用TLS协议发送邮件
  16. SMTP_ENABLE_STARTTLS_AUTO=true
  17. # 开启debug调式(有些邮箱必须在debug情况下才能使用)
  18. SMTP_DEBUG_OUTPUT=true
  19. # 是否有ssl校验 Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert', see
  20. SMTP_OPENSSL_VERIFY_MODE=none
  21. #发送等待时长
  22. RAILS_MAILER_TIMEOUT=60
  23. # 如果SMTP服务器需要,则注释掉以下环境变量
  24. #SMTP_TLS=false
  25. #SMTP_SSL=false
复制代码
注意:
  

  • 如果使用 Gmail 或 QQ 邮箱,需要启用“允许低安全性应用访问”或使用授权码而非直接密码。
  • 配置中邮箱和密码需与 SMTP 服务划一。
  

  • 自定义机器人
        1.生成chatwoot机器人token

   方式一:通过超等管理员背景(http://你的ip:3000/super_admin),生成机器人token
  
 

  
  方式二:通过 Rails控制台创建署理机器人
  

  • 进入rails容器
   
  1.  docker exec -it chatwoot-rails-1 sh
复制代码
   

  • 启动 rails 控制台
   
  1. bundle exec rails c
复制代码
   

  • 在 Rails 控制台中,输入以下命令来创建署理机器人并获取其访问令牌。生存检索到的令牌(token),因为在调用 chatwoot API 时需要使用它。
   
  1. # 在驻留bot逻辑时指定url
  2. # 如果传参了account_id属性来创建帐户bot,而不是全局bot
  3. bot = AgentBot.create!(name: "机器人名", outgoing_url: "http://localhost:8000")
  4. bot.access_token.token
复制代码
   

  • 为您的机器人添加头像(可选)
   
  1. avatar_file = Down.download("image url 你的头像图片链接")
  2. bot.avatar.attach(io: avatar_file, filename: avatar_file.original_filename, content_type: avatar_file.content_type)
复制代码
   

  • 通过运行以下命令将 Agent Bot 连接到您的收件箱
   
  1. # 取代的收件箱。首先使用Inbox.find(inbox_id)查找特定的收件箱
  2. AgentBotInbox.create!(inbox: Inbox.first, agent_bot: bot)
复制代码
           2.创建智能机器人对话服务系统(我用的是rasa)

   摆设文件我已经全部压缩,直接运行即可,下面是摆设文件下载地址:https://download.csdn.net/download/ko_10086/90192098
  注意:
       想更多了解rasa,请百度,我这里就不细讲了。
       我的对话模子仅为测试模子,如需更换成其它模子,将模子下载地址更换,重新运行即可
  

          4.测试 rasa服务API

   使用postman或者Apifox测试
   
  1. curl -X POST http://你的rasa的Ip:5005/webhooks/rest/webhook \
  2.      -H "Content-Type: application/json" \
  3.      -d '{"sender": "test_user", "message": "hello"}'
复制代码
   预期相应:
   
  1. [
  2.     {
  3.         "recipient_id": "test_user",
  4.         "text": "Hey! How are you?"
  5.     }
  6. ]
复制代码
           3.rasa与 chatwoot整合对接

   

  • 在chatwoot目次下创建middleware
  • 在middleware目次下创建一个app.py,来执行rasa与 chatwoot的交互
   
  1. # middleware/app.py
  2. from flask import Flask, request,jsonify
  3. import requests
  4. import os
  5. app = Flask(__name__)
  6. CHATWOOT_BOT_TOKEN = os.getenv("CHATWOOT_BOT_TOKEN")
  7. CHATWOOT_URL  = os.getenv("CHATWOOT_URL")
  8. RASA_URL = os.getenv("RASA_URL")
  9. @app.route('/rasa', methods=['POST'])
  10. def rasa():
  11.     data = request.get_json()
  12.     event = data.get('event')
  13.     if 'message_created' == event:
  14.         message_type = data['message_type']
  15.         message = data['content']
  16.         conversation = data['conversation']['id']
  17.         contact = data['sender']['id']
  18.         account = data['account']['id']
  19.         if (message_type == "incoming"):
  20.             bot_response = send_to_bot(contact, message)
  21.             create_message = send_to_chatwoot(account, conversation, bot_response)
  22.             print(create_message)
  23.     if 'automation_event.message_created' == event:
  24.         message = data['messages'][0]['content']
  25.         conversation = data['messages'][0]['conversation_id']
  26.         contact = data['messages'][0]['sender']['id']
  27.         account = data['messages'][0]['account_id']
  28.         message_type = data['messages'][0]['message_type']
  29.         if (message_type == 0):
  30.             bot_response = send_to_bot(contact, message)
  31.             create_message = send_to_chatwoot(account, conversation, bot_response)
  32.             print(create_message)
  33.             
  34.     return jsonify({"status": "success"}), 200
  35. def send_to_bot(sender, message):
  36.     data = {
  37.         'sender': sender,
  38.         'message': message
  39.     }
  40.     headers = {"Content-Type": "application/json",
  41.                "Accept": "application/json"}
  42.     r = requests.post(f'{RASA_URL}/webhooks/rest/webhook',
  43.                       json=data, headers=headers)
  44.     return r.json()[0]['text']
  45. def send_to_chatwoot(account, conversation, message):
  46.     data = {
  47.         'content': message
  48.     }
  49.     url = f"{CHATWOOT_URL}/api/v1/accounts/{account}/conversations/{conversation}/messages"
  50.     headers = {"Content-Type": "application/json",
  51.                "Accept": "application/json",
  52.                "api_access_token": f"{CHATWOOT_BOT_TOKEN}"}
  53.     r = requests.post(url,
  54.                       json=data, headers=headers)
  55.     return r.json()
  56. if __name__ == '__main__':
  57.     app.run(host='0.0.0.0', port=4000)
复制代码
   

  • 在middleware目次下创建一个 requirements.txt 文件来导入app.py相关工具
   
  1. Flask
  2. requests
复制代码
   

  • 在middleware目次下创建一个Dockerfile 文件来构建服务
   
  1. # middleware/Dockerfile
  2. FROM python:3.8-slim
  3. WORKDIR /app
  4. COPY requirements.txt requirements.txt
  5. RUN pip install --no-cache-dir -r requirements.txt
  6. RUN pip install --upgrade Jinja2 Flask
  7. COPY app.py .
  8. CMD ["python", "app.py"]
复制代码
   

  • chatwoot目次下的 docker-compose.yml 文件里加上middleware服务(上面已经加上了,取消解释即可),然后运行,如果运行不了,就单写一个docker-compose.yml文件来运行middleware服务
  • 运行命令:docker-compose down &&  docker-compose up -d --build
  4.测试智能机器人 

   

  • chatwoot的收件箱绑定好上面配置好的机器人
  

  

  • 在集成方式里面配置rasachatwoot交互的api,并选中对应交互变乱
  

  

  

  • 然后去客户端发送消息测试即可,如以下这样
  

  

  • 另有一种配置rasachatwoot交互的api的方式,即在Automation配置规则
  

  两种方式都是一样的
  

  • 队列分析和监控
   http://你chatwoot的ip:3000/monitoring/sidekiq

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

罪恶克星

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表