1

I am using converse.js to provide chat functionality. I am looking for a way to send some messages thru the API based on other buttons in the rest of the system.

var chat = converse.chats.open(jid);
chat.open();
chat.sendMessage(message);

chat.sendMessage() fails because the chatbox that has been returned only has limited functionality. https://conversejs.org/docs/html/development.html#the-chats-grouping

Should I override the wrappedChatBox functionality or is there a cleaner way to send a message? https://github.com/jcbrand/converse.js/blob/0746f2aa682b3a03a5c04a94570352e6921cde86/src/converse-core.js#L273

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
sww314
  • 1,252
  • 13
  • 17

2 Answers2

1

This is probably a bit more lower-level than you'd like, but you can send message stanzas via converse.send(stanza);

So, to send a chat message:

var msg = converse.env.$msg({
     from: 'juliet@example.com/balcony',
     to:'romeo@example.net',
     type:'chat'
});
converse.send(msg);

That said, I think the wrapper can be extended to add a send method there as well (check in next release).

JC Brand
  • 2,652
  • 18
  • 18
0

This is quite an old question but it seems that the answer has changed so I just wanted to comment here for those who come along in the future. I am writing a converse headless app and I had to use _converse.api.send()

The _converse object is accessed by creating a plugin.

vision_m
  • 1
  • 3