sulla
sulla copied to clipboard
[feat] Make all send functions work even if no chat exists
Actually the only method that work in case a chat doesn't exists is sendMessageToId
It basically works by getting the first chat model in store, force to change the chat id (the number to send the message) and use it's sendMessage function to send a message.
I basically suggest to create a WAPI method
window.WAPI.getChat = function(chatId, done) {
const idUser = new Store.WidFactory.createWid(chatid);
Store.Chat.find(idUser).then((chat) => {
if(!chat) {
// firstly check if there is a contact and if not use the trick used in sendMessageToId
}
})
}
In this way we can use this function in all methods that send something to a chat to make them work even without an existing chat
It is a good idea, however, I would like to keep wapi.js
functions as agnostic as possible.
I rather adding this in sulla side so sulla can be the smart part of wapi, just have to check if it doesn't affect performance
@danielcardeenas The other easier solution so would be to send caption using sendMessageToId
if no chat is found and then send the file/location/giphy or everything wanted