Is there any way to send a message automatically, I found a sendMessage trigger but it doesn't work, maybe I am doing wrong something
export const msgUser = (viewerChannelCredentials: any) => {
const {username, channel} = viewerChannelCredentials;
window.converse.plugins.add('msg-user', {
dependencies: [],
initialize: async function () {
const _converse = this._converse;
return _converse.api.trigger('sendMessage', {
chatbox: _converse.ChatBox | _converse.ChatRoom,
message: 'abc',
});
},
});
};
Another solution found that also doesn't work, it throws an error which Cannot read properties of undefined (reading '$msg')
export const msgUser = (viewerChannelCredentials: any) => {
const {username, channel} = viewerChannelCredentials;
window.converse.plugins.add('msg-user', {
dependencies: [],
initialize: async function () {
const _converse = this._converse;
var msg = _converse.env.$msg({
from: '[email protected]/balcony',
to: '[email protected]',
type: 'chat',
});
_converse.send(msg);
},
});
};
Calling
api.trigger('sendMessage'only fires an event with the name "sendMessage", it doesn't actually send a message.To send a message, you can call the
sendMessagemethod on aChatBox.For example: