本文分三部分系统介绍如何开发一套在线客服系统聊天源码,该源码基于ThinkPHP,代码完全开源。
  首先,我们只使用@auth指令。
  其次,我们添加一个带有参数的订阅类型。
  第三,我们更新@auth指令和订阅类型。
  完整源码:kf.zxkfym.top
  1 使用@auth指令并执行身份验证
  添加和使用身份验证

$ amplify add auth
Scanning for plugins...
Plugin scan successfulUsing service: Cognito, provided by: awscloudformationThe current configured provider is Amazon Cognito. Do you want to use the default authentication and security configuration? Default configurationWarning: you will not be able to edit these selections. How do you want users to be able to sign in? UsernameDo you want to configure advanced settings? No, I am done.
Successfully added auth resource sampleamplifysubscriXXXXXXXX locallySome next steps:
"amplify push" will build all your local backend resources and provision it in the cloud
"amplify publish" will build all your local backend and frontend resources (if you have hosting category added) and provision it in the cloud$
$ amplify push✔ Successfully pulled backend environment dev from the cloud.Current Environment: dev| Category | Resource name                | Operation | Provider plugin   |
| -------- | ---------------------------- | --------- | ----------------- |
| Auth     | sampleamplifysubscriXXXXXXXX | Create    | awscloudformation |
| Api      | sampleamplifysubscri         | No Change | awscloudformation |
? Are you sure you want to continue? Yes
⠙ Updating resources in the cloud. This may take a few minutes...(snip)✔ All resources are updated in the cloud$

然后,更新 api。

$ amplify update api
? Please select from one of the below mentioned services: GraphQL
? Select from the options below Update auth settings
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Configure additional auth types? NoThe following types do not have '@auth' enabled. Consider using @auth with @model- OpenChat- RoomChat
Learn more about @auth here: https://docs.amplify.aws/cli/graphql-transformer/authGraphQL schema compiled successfully.Edit your schema at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema.graphql or place .graphql files in a directory at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema
The API_KEY auth type has been removed from the API.
If other resources depend on this API, run "amplify update <category>" and reselect this API to remove the dependency on the API key.
⚠️  This must be done before running "amplify push" to prevent a push failure
Successfully updated resource
$

  这意味着,我们可以使用@auth指令并且只能使用userPools.
  更新 graphql 模式文件。

type CloseRoomChat@model@auth(rules: [{ allow: owner, provider: userPools }]) {id: ID!roomName: String!message: String!
}
$ amplify push
✔ Successfully pulled backend environment dev from the cloud.Current Environment: dev| Category | Resource name                | Operation | Provider plugin   |
| -------- | ---------------------------- | --------- | ----------------- |
| Api      | sampleamplifysubscri         | Update    | awscloudformation |
| Auth     | sampleamplifysubscriXXXXXXXX | No Change | awscloudformation |
? Are you sure you want to continue? YesThe following types do not have '@auth' enabled. Consider using @auth with @model- OpenChat- RoomChat
Learn more about @auth here: https://docs.amplify.aws/cli/graphql-transformer/authGraphQL schema compiled successfully.Edit your schema at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema.graphql or place .graphql files in a directory at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema
? Do you want to update code for your updated GraphQL API Yes
? Do you want to generate GraphQL statements (queries, mutations and subscription) based on your schema types?
This will overwrite your current graphql queries, mutations and subscriptions Yes
⠴ Updating resources in the cloud. This may take a few minutes...(snip)✔ Generated GraphQL operations successfully and saved at src/graphql
✔ All resources are updated in the cloudGraphQL endpoint: https://XXXXXXXXXXXXXXXXXXXXXXXXXX.appsync-api.ap-northeast-1.amazonaws.com/graphql$

  实现登录页面。
  实施封闭式聊天页面。

<template><v-container><v-row><v-col cols="12"><v-card><v-card-title>Multi-room Close Chat</v-card-title><v-card-text>Only authenticated users can use this chat. All subscriptions arereceived.</v-card-text></v-card></v-col></v-row><v-row><v-col cols="12"><v-text-fieldv-model="inputMessage"label="New Message"outlinedclearableappend-outer-icon="mdi-send"@click:append-outer="sendMessage"></v-text-field></v-col></v-row><v-tabsv-model="roomName"background-color="primary"center-activecentereddark><v-tabv-for="(room, index) in rooms":key="index":href="'#' + room"@click="setSubscribeByRoomName(room)">{{ room }}</v-tab></v-tabs><v-card flat><v-tabs-items v-model="roomName"><v-tab-item v-for="(room, index) in rooms" :key="index" :value="room"><v-row class="pa-2"><v-col cols="6"><ChatList title="Input" :list="messages[room]"></ChatList></v-col><v-col cols="6"><ChatListtitle="Subscriptions":list="subscriptionMessages[room]"></ChatList></v-col></v-row></v-tab-item></v-tabs-items></v-card></v-container>
</template><script>
import { Auth, API, graphqlOperation } from 'aws-amplify'
import { createCloseRoomChat } from '@/graphql/mutations'
import { onCreateCloseRoomChat } from '@/graphql/subscriptions'import ChatList from '@/components/ChatList'export default {components: { ChatList },data: function() {return {user: null,roomName: null,inputMessage: '',rooms: ['room1', 'room2'],messages: {room1: [],room2: [],},subscriptionMessages: {room1: [],room2: [],},onCreateMultiRoomChatSubscriptions: {room1: null,room2: null,},}},created: async function() {this.user = await Auth.currentUserInfo()this.setSubscribeByRoomName('room1')},beforeDestroy: function() {this.clearSubscriptions()},methods: {sendMessage: async function() {const message = await API.graphql(graphqlOperation(createCloseRoomChat, {input: { message: this.inputMessage, roomName: this.roomName },}),)console.log(message)this.messages[this.roomName].push(message.data.createCloseRoomChat)this.inputMessage = ''},setSubscribeByRoomName(roomName) {this.clearSubscriptions()this.onCreateMultiRoomChatSubscriptions[roomName] = API.graphql(graphqlOperation(onCreateCloseRoomChat, { owner: this.user.username }),).subscribe({next: ({ provider, value }) => {console.log({ provider, value })this.subscriptionMessages[value.data.onCreateCloseRoomChat.roomName].push(value.data.onCreateCloseRoomChat)},})},clearSubscriptions() {this.rooms.forEach(room => {if (this.onCreateMultiRoomChatSubscriptions[room]) {this.onCreateMultiRoomChatSubscriptions[room].unsubscribe()}this.onCreateMultiRoomChatSubscriptions[room] = null})},},
}
</script><style></style>

重要的一点就在这里。

(snip)import { Auth, API, graphqlOperation } from 'aws-amplify'
import { createCloseRoomChat } from '@/graphql/mutations'
import { onCreateCloseRoomChat } from '@/graphql/subscriptions'(snip)created: async function() {this.user = await Auth.currentUserInfo()this.setSubscribeByRoomName('room1')},(snip)sendMessage: async function() {const message = await API.graphql(graphqlOperation(createCloseRoomChat, {
...this.messages[this.roomName].push(message.data.createCloseRoomChat)
...(snip)setSubscribeByRoomName(roomName) {this.clearSubscriptions()this.onCreateMultiRoomChatSubscriptions[roomName] = API.graphql(graphqlOperation(onCreateCloseRoomChat, { owner: this.user.username }),
...this.subscriptionMessages[value.data.onCreateCloseRoomChat.roomName].push(value.data.onCreateCloseRoomChat)
...(snip)

  createCloseRoomChat使用与createRoomChat
  onCreateCloseRoomChat使用而不是onCreateRoomChat
  并且,onCreateCloseRoomChat需要有论据owner。
  owner信息是这样得到的。
  this.user = await Auth.currentUserInfo()
  this.user.username // your sign-in username
  无论如何,现在我们可以查看我们的第一个“在线客服系统”。
  但是当你尝试这个时,你可能会有点失望。
  您发布消息并接收自己的消息。
  接下来,您打开另一个浏览器,登录另一个用户,打开“客服系统”,然后发布消息。
  您无法在原始浏览器上收到另一条消息。
  2 添加带参数的订阅类型
  更新 graphql 架构
  因此,我们添加了一个 Subscription 类型,其参数roomName类似于onCreateRoomChatByRoomName上一篇文章中添加的参数。
  更新 graphql 模式文件。

type Subscription {onCreateRoomChatByRoomName(roomName: String!): RoomChat@aws_subscribe(mutations: ["createRoomChat"])onCreateCloseRoomChatByRoomName(roomName: String!): CloseRoomChat@aws_subscribe(mutations: ["createCloseRoomChat"])
}
$ amplify push
✔ Successfully pulled backend environment dev from the cloud.Current Environment: dev| Category | Resource name                | Operation | Provider plugin   |
| -------- | ---------------------------- | --------- | ----------------- |
| Api      | sampleamplifysubscri         | Update    | awscloudformation |
| Auth     | sampleamplifysubscriXXXXXXXX | No Change | awscloudformation |
? Are you sure you want to continue? YesThe following types do not have '@auth' enabled. Consider using @auth with @model- OpenChat- RoomChat
Learn more about @auth here: https://docs.amplify.aws/cli/graphql-transformer/authGraphQL schema compiled successfully.Edit your schema at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema.graphql or place .graphql files in a directory at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema
? Do you want to update code for your updated GraphQL API Yes
? Do you want to generate GraphQL statements (queries, mutations and subscription) based on your schema types?
This will overwrite your current graphql queries, mutations and subscriptions Yes
⠴ Updating resources in the cloud. This may take a few minutes...(snip)✔ All resources are updated in the cloudGraphQL endpoint: https://XXXXXXXXXXXXXXXXXXXXXXXXXX.appsync-api.ap-northeast-1.amazonaws.com/graphql$

更新封闭聊天

<template><v-container><v-row><v-col cols="12"><v-card><v-card-title>Multi-room Close Chat</v-card-title><v-card-text>Only authenticated users can use this chat. All subscriptions arereceived.</v-card-text></v-card></v-col></v-row><v-row><v-col cols="12"><v-text-fieldv-model="inputMessage"label="New Message"outlinedclearableappend-outer-icon="mdi-send"@click:append-outer="sendMessage"></v-text-field></v-col></v-row><v-tabsv-model="roomName"background-color="primary"center-activecentereddark><v-tabv-for="(room, index) in rooms":key="index":href="'#' + room"@click="setSubscribeByRoomName(room)">{{ room }}</v-tab></v-tabs><v-card flat><v-tabs-items v-model="roomName"><v-tab-item v-for="(room, index) in rooms" :key="index" :value="room"><v-row class="pa-2"><v-col cols="6"><ChatList title="Input" :list="messages[room]"></ChatList></v-col><v-col cols="6"><ChatListtitle="Subscriptions":list="subscriptionMessages[room]"></ChatList></v-col></v-row></v-tab-item></v-tabs-items></v-card></v-container>
</template><script>
import { Auth, API, graphqlOperation } from 'aws-amplify'
import { createCloseRoomChat } from '@/graphql/mutations'
import { onCreateCloseRoomChatByRoomName } from '@/graphql/subscriptions'import ChatList from '@/components/ChatList'export default {components: { ChatList },data: function() {return {user: null,roomName: null,inputMessage: '',rooms: ['room1', 'room2'],messages: {room1: [],room2: [],},subscriptionMessages: {room1: [],room2: [],},onCreateMultiRoomChatSubscriptions: {room1: null,room2: null,},}},created: async function() {this.user = await Auth.currentUserInfo()this.setSubscribeByRoomName('room1')},beforeDestroy: function() {this.clearSubscriptions()},methods: {sendMessage: async function() {const message = await API.graphql(graphqlOperation(createCloseRoomChat, {input: { message: this.inputMessage, roomName: this.roomName },}),)console.log(message)this.messages[this.roomName].push(message.data.createCloseRoomChat)this.inputMessage = ''},setSubscribeByRoomName(roomName) {this.clearSubscriptions()this.onCreateMultiRoomChatSubscriptions[roomName] = API.graphql(graphqlOperation(onCreateCloseRoomChatByRoomName, {roomName: roomName,}),).subscribe({next: ({ provider, value }) => {console.log({ provider, value })this.subscriptionMessages[value.data.onCreateCloseRoomChatByRoomName.roomName].push(value.data.onCreateCloseRoomChatByRoomName)},})},clearSubscriptions() {this.rooms.forEach(room => {if (this.onCreateMultiRoomChatSubscriptions[room]) {this.onCreateMultiRoomChatSubscriptions[room].unsubscribe()}this.onCreateMultiRoomChatSubscriptions[room] = null})},},
}
</script><style></style>

  并且,onCreateRoomChatByRoomName需要有论据roomName。
  你试试这个程序,你可以收到另一个用户的消息。
  这意味着,“只有授权用户才能发布使用在线客服系统。”
  3、但是,我们经常使用“授权用户可以发布但所有用户都可以阅读”的系统。
  所以,我们做到了。
  更新多授权api
  以前,我们只使用Amazon Cognito User Pool.
  在这里,我们使用Amazon Cognito User Pool和API key。

$ amplify update api
? Please select from one of the below mentioned services: GraphQL
? Select from the options below Update auth settings
? Choose the default authorization type for the API Amazon Cognito User Pool
Use a Cognito user pool configured as a part of this project.
? Configure additional auth types? Yes
? Choose the additional authorization types you want to configure for the API API key
API key configuration
? Enter a description for the API key:
? After how many days from now the API key should expire (1-365): 365The following types do not have '@auth' enabled. Consider using @auth with @model- OpenChat- RoomChat
Learn more about @auth here: https://docs.amplify.aws/cli/graphql-transformer/authGraphQL schema compiled successfully.Edit your schema at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema.graphql or place .graphql files in a directory at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema
The API_KEY auth type has been added to the API.
⚠️  If other resources depend on this API and need access to the API key, run "amplify update <category>" and reselect this API as a dependency to add the API key dependency.
Successfully updated resource
$

  然后,更新 graphql 模式文件。
  更新@auth指令和订阅:

type CloseRoomChat@model@auth(rules: [{ allow: owner, provider: userPools }{ allow: public, provider: apiKey, operations: [read] }]) {id: ID!roomName: String!message: String!
}type Subscription {onCreateRoomChatByRoomName(roomName: String!): RoomChat@aws_subscribe(mutations: ["createRoomChat"])onCreateCloseRoomChatByRoomName(roomName: String!): CloseRoomChat@aws_subscribe(mutations: ["createCloseRoomChat"])@aws_api_key
}

  注意:
  @aws_api_key不在“放大文档”中。

$ amplify push
✔ Successfully pulled backend environment dev from the cloud.Current Environment: dev| Category | Resource name                | Operation | Provider plugin   |
| -------- | ---------------------------- | --------- | ----------------- |
| Api      | sampleamplifysubscri         | Update    | awscloudformation |
| Auth     | sampleamplifysubscriXXXXXXXX | No Change | awscloudformation |
? Are you sure you want to continue? YesThe following types do not have '@auth' enabled. Consider using @auth with @model- OpenChat- RoomChat
Learn more about @auth here: https://docs.amplify.aws/cli/graphql-transformer/authGraphQL schema compiled successfully.Edit your schema at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema.graphql or place .graphql files in a directory at /[YOUR_DIRECTORY]/sample-amplify-subscriptions/amplify/backend/api/sampleamplifysubscri/schema
? Do you want to update code for your updated GraphQL API Yes
? Do you want to generate GraphQL statements (queries, mutations and subscription) based on your schema types?
This will overwrite your current graphql queries, mutations and subscriptions Yes
⠧ Updating resources in the cloud. This may take a few minutes...(snip)✔ All resources are updated in the cloudGraphQL endpoint: https://XXXXXXXXXXXXXXXXXXXXXXXXXX.appsync-api.ap-northeast-1.amazonaws.com/graphql
GraphQL API KEY: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX$

  最后,我们得到了“授权用户可以发帖,所有用户都可以使用在线客服聊天系统。
  您打开浏览器并打开“封闭聊天”(使用非授权用户)。
  然后,您打开另一个浏览器,登录另一个用户,打开“客服系统”,然后发布消息。
  您可以在原始浏览器上接收消息!

多国语言在线客服系统源码+软件下载二合一集成相关推荐

  1. 最新在线客服系统源码软件代码+自动回复+管理后台

    正文: 完整标题: PHP在线客服系统源码是一款PHP开发的在线客服系统源码,网站在线客服系统,网页在线客服软件代码,免费在线客服系统源码,支持多商家多客服,客服系统源码支持二开,客服同时支持手机移动 ...

  2. 在线客服系统源码软件代码+自动回复+可生成接入+手机版管理后台

    介绍: PHP在线客服系统源码是一款PHP开发的在线客服系统源码,网站在线客服系统,网页在线客服软件代码,免费在线客服系统源码,支持多商家多客服,客服系统源码支持二开,客服同时支持手机移动端和PC网页 ...

  3. 多语言在线客服系统源码-自动识别中英环境-私有化部署完美支持跨境电商网站...

    如果您的客户遍布全球,客户沟通就必须跨越语言障碍.用客户当地的语言跟他们交谈,可以帮助您在客户生命周期的所有阶段建立信任,当然也包括服务支持. 具体做法,看看这四点建议吧~ 1.使用当地语言开展服务 ...

  4. 智能在线客服系统源码 国际版多语言多商户智能机器人源码

    一套智能在线客服系统源码 多商户网页客服系统源码 支持二十种国际语言 带机器人自动回复. 框架:Thinkphp5+workerman, 环境:nginx+php7.3+mysql5.6 支持H5+公 ...

  5. 【客服系统】在线客服系统源码外贸聊天通讯带翻译多语言支持网页安卓苹果打包封装APP

    随着全球化的加速推进,外贸行业对于在线客服系统的需求日益增长.一款功能强大.支持多语言交流.适用于网页和移动端的在线客服系统源码成为了众多企业的首选.本文将介绍一款名为"外贸聊天通讯带翻译多 ...

  6. 亲测无限坐席在线客服系统源码,基于ThinkPHP的一款在线客服系统源码

    源码简介 东西没问题,和别人换的本来说是多语言带机器人翻译之类的,给了个这... 直接一键安装的,启动两个端口就行了,安装倒是简单 编号:ym270 品牌:无 语言:PHP 大小:34.5MB 类型: ...

  7. 防黑运营版在线客服系统源码/多商户机器人/自助注册客服系统源码/im即时通讯聊天系统源码

    ☑️ 编号:ym213 ☑️ 品牌:thinkPHP ☑️ 语言:php ☑️ 大小:99MB ☑️ 类型:在线客服系统源码 ☑️ 支持:im即时通讯

  8. PHP多商户AI智能在线客服系统源码 机器人自动回复 即时通讯聊天系统源码

    一套智能在线客服系统源码 多商户网页客服系统源码 支持二十种国际语言 带机器人自动回复. 框架:Thinkphp5+workerman, 环境:nginx+php7.3+mysql5.6 支持H5+公 ...

  9. 价值1000元的稀有二开版的无限坐席在线客服系统源码+教程

    demo软件园每日更新资源,请看到最后就能获取你想要的: 1.价值1000元的稀有二开版的无限坐席在线客服系统源码+教程 价值1000元的稀有二开版的无限坐席在线客服系统源码 直接一键安装的,启动两个 ...

最新文章

  1. 牛人博客!!!各大招聘网站信息实时查询浏览【转】
  2. Android图片压缩(质量压缩和尺寸压缩)
  3. mysql数据库迁移到另一台电脑上
  4. 提升漏洞修复率,DevSecOps真的很有一套
  5. jQuery form表单的serialize()参数和其他参数 如何一起传给后端
  6. mktime 夏令时
  7. linux脚本基础详解
  8. 茆诗松等《高等数理统计(第二版)》例 1.28 的错误及改正
  9. Linux下fat32文件系统变为只读
  10. 波峰波谷(凸点凹点)的检测算法
  11. CNI Proposal 摘要
  12. python12306抢票_Python 12306 的抢票工具
  13. 强大的类似qq截图或者微信截图功能软件
  14. Go语言学习之路(二)
  15. 一些javascript内容
  16. 11 wifi6速率_实测:华硕、华为、小米、水星,千元以内的wifi6路由器哪家强?...
  17. varchar(50)中50的涵义
  18. excel中html批量转化为pdf文件,如何将大量的Excel转换成PDF?
  19. java 标签云_网站标签云(TagCloud)的实现
  20. 台灯AAA和AA有什么区别?国AA台灯有必要买吗

热门文章

  1. 快手极速版56位 sig3
  2. python openstack vpc互通_深入浅出新一代云网络——VPC中的那些功能与基于OpenStack Neutron的实现(二)-带宽控制...
  3. 《操作系统设计原理》第一章习题
  4. css 一些好玩的属性,css一些不常见但很有用的属性操作大全
  5. linux 编辑器下复制粘贴,Linux-vim编辑器 常用命令 复制粘贴
  6. 解决开机出现“CLIENT MAC ADDR”的问题
  7. a12处理器和骁龙855_手机处理器排名,骁龙855只排第三,第一就是第一
  8. BlackBerry简单计数器
  9. 淘宝接口调用,面向对象
  10. java 内存 pdf_jvm内存模型高清版.pdf