聊天引擎API支持聊天通过React

发布于 2025-01-21 12:45:03 字数 2532 浏览 1 评论 0原文

如果有人熟悉,我正在使用聊天引擎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: '[email protected]', 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函数中所述。为什么管理用户名总是输入的电子邮件地址???

这是根据文档通过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
  },

管理员是数组中的第一个索引。就像我的。

I am using Chat Engine io if anyone is familiar with it. It is an API for chat rooms that you can implement into your application. I created an application that contains a support chat where the admin can chat with the email input user.

I have tried every possible way, read through documentation and still can not assign the admin to the already created user which is the admin.

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 function that is inside SupportWindow.js component

  const [email, setEmail] = useState("");

  const handleSubmit = () => {
    createUser(email,
      user => {
        createChat(email,
          chat => console.log('success', chat)
        )
      }
    )
  };

This is the console for the response returned...

{id: 111480, admin: {…}, people: Array(2), attachments: Array(0), last_message: {…}, …}
access_key: "*****************************"
admin: {username: '[email protected]', 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

The admin username SHOULD BE "Tim", as declared in the createChat.js function. Why is the admin username always the entered email address???

This is the instructed way of setting up your PUT call via axios as per docs.

--data-raw '{
    "usernames": ["adam_la_morre", "bob_baker", "wendy_walker"],
    "title": "Another Surprise Party!",
    "is_direct_chat": false
}'

RESULT:

{
  "id": 38702,
  "admin": {
    "username": "adam_la_morre",
    "first_name": "Adam",
    "last_name": "La Morre",
    "avatar": null,
    "custom_json": {
      "custom_json": 2001
    },
    "is_online": false
  },

The admin is the first index in the array. Just like mine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弄潮 2025-01-28 12:45:03

在您的createuser中,您将设置用户名 <代码>电子邮件。如果要将用户名设置为它,则需要将名称传递给它。

  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)
    })
};

另外,您将秘密设置为电子邮件。

In your createUser you are setting username to email. You'll need to pass the name in if you want to set username to it.

  const handleSubmit = () => {
    createUser(email, userName,
      user => {
        createChat(email,
          chat => console.log('success', chat)
        )
      }
    )
  };

Then in your 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)
    })
};

Also, you are setting secret to email.

你的呼吸 2025-01-28 12:45:03

我找到了这个解决方案。
“用户名”:[“ adam_la_morre”,“ bob_baker”,]
第一个索引必须启动字母A,例如(AAA01)。如果管理用户名是用户名,则小于用户名更改管理用户名
(例如“用户名”:[“ bob_baker”,“ adam_la_morre”,]。
ADAM_LA_MORRE成为管理用户名。

I found this solution.
"usernames": ["adam_la_morre", "bob_baker",]
the first index must start alphabet A, eg(aaa01). if the admin username is username less than the username will change the admin username
(eg "usernames": ["bob_baker", "adam_la_morre",].
adam_la_morre becomes the admin username.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文