Closed aravi365 closed 3 years ago
Here is how it looks like:
Is there anything I missed? These are the codes i used for initialising and signing in
async function initChat() {
const CREDENTIALS = {
appId: 4xxx,
authKey: xxxx,
authSecret: xxxx',
};
const CONFIG = {
debug: {mode: 1}, // enable DEBUG mode (mode 0 is logs off, mode 1 -> console.log())
};
ConnectyCube.init(CREDENTIALS, CONFIG);
}
async function signin() {
ConnectyCube.createSession()
.then((session) => {
console.log('session', session);
})
.catch((error) => {
console.log('session err', error);
});
const userCredentials = {
userId: 35278xx,
password: 'xxxxx',
};
ConnectyCube.chat
.connect(userCredentials)
.then(() => {})
.catch((error) => {
console.warn(error);
});
}
There are 2 issues: 1) you have to login or create a session with user, e.g.
either create a session with user creds in one go
const userCredentials = { login: "cubeuser", password: "awesomepwd" };
ConnectyCube.createSession(userCredentials)
.then((session) => {
console.log('session', session);
})
.catch((error) => {
console.log('session err', error);
});
or create session and then login:
ConnectyCube.createSession()
.then((session) => {
console.log('session', session);
const userCredentials = { login: "cubeuser", password: "awesomepwd" };
ConnectyCube.login(userCredentials)
.then((user) => {})
.catch((error) => {});
})
.catch((error) => {
console.log('session err', error);
});
https://developers.connectycube.com/js/authentication-and-users?id=upgrade-session-token-user-login
const userCredentials = { login: "cubeuser", password: "awesomepwd" };
ConnectyCube.createSession(userCredentials)
.then((session) => {
console.log('session', session);
/// HERE YOU CAN CREATE A CHAT NOW
})
.catch((error) => {
console.log('session err', error);
});
It worked but when sending messages, the connection status shows false and message is not sent, but i am getting a message id in the response. Here is my helper method for sending message
export const sendMessage = async (messageText) => {
const opponentId = xyxyxyxy;
const dialogId = 'xxxxxxxxxxxxxxxxxxxxx';
const message = {
type: 3,
body: messageText,
extension: {
save_to_history: 1,
dialog_id: dialogId,
},
markable: 1,
};
const userCredentials = {
login: 'xxxx@xxxxxx.xxx',
password: 'xxxxxx',
};
try {
const isConnected = await ConnectyCube.chat.isConnected;
console.log('CONNECTION STATUS', isConnected);
let msgId = await ConnectyCube.chat.send(opponentId, message);
console.log('response after send', msgId);
} catch (err) {
console.log(err);
}
};
Here are the logs @DaveLomber
Tried to create a dialog but it gives me and error: 403: "Forbidden. Need user"
I am stuck here without any ways to troubleshoot what went wrong!