Kruiser8 / Kruiz-Control

Kruiz Control enables a pseudo code approach to manage and automatically handle Twitch Channel Points, Twitch Chat, OBS or SLOBS, and StreamElements or Streamlabs alerts.
Other
234 stars 32 forks source link

How to call API and send response to Chat #59

Closed Epyxx closed 1 year ago

Epyxx commented 1 year ago

Hey there, i want to call an API url and send the response text to the chat i tried the following but it did not work:

OnCommand bm 0 !next API GET http://localhost/api.php?action=next Chat Send "{api_data}"

and

OnCommand bm 0 !next API GET http://localhost/api.php?action=next Chat Send "{response}"

what is the correct way to do this?

Thanks!

Kruiser8 commented 1 year ago

Hey Epyxx,

The first option you send is correct. API response data is available as the api_data parameter. Did you get any value sent to chat like Error?

Something to note, OBS 27+ updated the browser source and any locally hosted APIs will need to include an Access-Control-Allow-Origin header value to allow OBS to call them.

<?php
header("Access-Control-Allow-Origin: *");

Thanks, Kruiser

Epyxx commented 1 year ago

Thanks! The header was the problem :) Before i got no response at all, there were no message sent to chat. But now with the header it works! :D