Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Does sendChat with callback only work with rolls?

Hello. When using sendChat with callback to get output from another script, all I get as return content is the same api command I sent using the sendChat call in the first place. Is there something special that needs to be done or is it not possible using it in that way? I use this to send the message and  wait for the reply: const somefunction=()=>{     let message="!anotherApiScript -withSomeArgs";     let result=await fetchChat(message); } const fetchChat = message => new Promise(resolve => sendChat('',message,resolve)); result would then be:  [{"who":"","type":"api","content":" !anotherApiScript -withSomeArgs ","playerid":"API","avatar":false,"inlinerolls":[]}] I was hoping "content" would be the chat output from !anotherApiScript If I instead send a roll command like let message="/roll 1d10" the result would be [{"who":"","type":"rollresult","content":"{\"type\":\"V\",\"rolls\":[{\"type\":\"R\",\"dice\":1,\"sides\":10,\"mods\":{},\"results\":[{\"v\":9}]}],\"resultType\":\"sum\",\"total\":9}","playerid":"API","avatar":false,"origRoll":"1d10","signature":"3ce3389579ee4bed86021a04567328b083572c61dcd083d7a7e415d805f079f5a2b39e03292a018c922b5974e06fb8453636d304a34712c6af86ed5e7ea0280c","_fbid":"-NEPnsx2V43K35kqYdlB","inlinerolls":[]}] "content" is then the output from QuantumRoll server as a JSON string. Anyone know how to get the chat output from another api script?
1665833228
Oosh
Sheet Author
API Scripter
sendChat has internal code which treats rolls as a special case - it waits for the roll server's response to send a return to sendChat's callback. Sending this: !anotherApiScript -withSomeArgs Is just a string, so the callback immediately resolves. There's no code connecting that string to any further functionality. The fact that it triggers a handler in another user script is completely unrelated to sendChat's callback. To listen for another scripts output, just use a regular old handleInput on('chat:message', (msg) => { /* do things */ }); You'll need some way of detecting if it's the right message. You can narrow it down by only listening for a brief window after you send your command, then disabling your handleInput (you need to do this manually, as the .off() handler destroyers aren't exposed to the sandbox AFAIK). Which script are you trying to communicate with? You could just hack a function into it so it you can attach a handler directly, that would be much cleaner.
Thx, that's what I figured. Was hoping I was wrong, though.