Do you know cometchat?
cometchat is a chat API & message SDK that allows you to easily set up a chat function on your website.
I used this comet at pro (cometch at's more flexible service) API to add chat functionality to my site. (Implemented in python (Django) based on here) But after completion, a tragedy will occur.
I can't send Japanese text with cometchat. .. .. .. My site is in Japanese
The site has become international.
The official document says, "Japanese is also supported!" Actually, when I try to send a message in Japanese, I get the following error.
UnicodeEncodeError: 'latin-1' codec can't encode characters
in position 90-92: Body ('Ah ah') is not valid Latin-1.
Use body.encode('utf-8') if you want to send it encoded in UTF-8.
Use body.encode ('utf-8') ← The above error tells me that I should try this, If you try, ERR_BAD_REQUEST will be returned.
{"error":{"code":"ERR_BAD_REQUEST","details":{"receiver":["The
receiver field is required."],"receiverType":["The receiver
type field is required."]},"message":"Failed to validate the
data sent with the request."}}
When sending a message. Convert to byte and convert to hexadecimal character string.
text = "Message you want to send"
text.encode().hex()
# 'e98081e3828ae3819fe38184e383a1e38383e382bbe383bce382b8'
When receiving a message. Converts a hexadecimal string to bytes and bytes to str.
bytes.fromhex(text).decode()
# "Message you want to send"
Recommended Posts