我正在使用聊天引擎io,如果有人熟悉它。它是一个用于聊天室的API,您可以在应用程序中实现它。我创建了一个应用程序,其中包含一个支持聊天,管理员可以与电子邮件输入用户聊天。
我已经尝试了每一种可能的方式,阅读文档,仍然不能分配管理员给已经创建的用户,也就是管理。
createChat.js
const createChat = (email, callBack) => {
axios
.put(
"https://api.chatengine.io/chats/",
{
"usernames": ["Tim", email],
"is_direct_chat": true,
},
{ headers: { "Private-Key": process.env.REACT_APP_CE_PRIVATE_KEY } }
)
.then((r) => callBack(r.data))
.catch((error) => {
console.error("there was an error", error);
});
};createUser.js
const createUser = (email, callBack) => {
axios
.put(
"https://api.chatengine.io/users/",
{
"username": email,
"secret": email,
"email": email,
},
{ headers: { "Private-Key": process.env.REACT_APP_CE_PRIVATE_KEY } }
)
.then((r) => callBack(r.data))
.catch(error => {
console.error('there was an error', error)
})
};在handleSubmit组件中的SupportWindow.js函数
const [email, setEmail] = useState("");
const handleSubmit = () => {
createUser(email,
user => {
createChat(email,
chat => console.log('success', chat)
)
}
)
};这是返回响应的控制台..。
{id: 111480, admin: {…}, people: Array(2), attachments: Array(0), last_message: {…}, …}
access_key: "*****************************"
admin: {username: 'e@e.com', first_name: '', last_name: '', avatar: null, custom_json: '{}', …}
attachments: []
created: "2022-04-14T23:36:49.934306Z"
custom_json: "{}"
id: 111480
is_authenticated: true
is_direct_chat: true
last_message: {created: '', attachments: Array(0), sender_username: '', text: '', custom_json: ''}
people: (2) [{…}, {…}]
title: null管理用户名应该是"Tim",在createChat.js函数中声明。为什么管理员用户名总是输入电子邮件地址?
这是按照docs通过axios设置PUT调用的指示方式。
--data-raw '{
"usernames": ["adam_la_morre", "bob_baker", "wendy_walker"],
"title": "Another Surprise Party!",
"is_direct_chat": false
}'结果:
{
"id": 38702,
"admin": {
"username": "adam_la_morre",
"first_name": "Adam",
"last_name": "La Morre",
"avatar": null,
"custom_json": {
"custom_json": 2001
},
"is_online": false
},admin是数组中的第一个索引。就像我的一样。
发布于 2022-04-15 00:22:38
在您的createUser中,您将username设置为email。如果要将username设置为它,则需要传递名称。
const handleSubmit = () => {
createUser(email, userName,
user => {
createChat(email,
chat => console.log('success', chat)
)
}
)
};然后在你的createUser
const createUser = (email, userName, callBack) => {
axios
.put(
"https://api.chatengine.io/users/",
{
"username": userName,
"secret": email,
"email": email,
},
{ headers: { "Private-Key": process.env.REACT_APP_CE_PRIVATE_KEY } }
)
.then((r) => callBack(r.data))
.catch(error => {
console.error('there was an error', error)
})
};同时,你也在为电子邮件设置秘密。
https://stackoverflow.com/questions/71878664
复制相似问题