Edits history of script submission #21041 for ' Fusion AI (Search & Chat) (yelp)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Yelp = {
      apiKey: string;
    };
    /**
     * Fusion AI (Search & Chat)
     * The Fusion AI endpoint brings conversational intelligence to your applications, enabling users to ask natural language questions and receive real-time, contextually relevant answers powered by Yelp’s latest business data and reviews.
     */
    export async function main(
      auth: Yelp,
      body: {
        query: string;
        chat_id?: string;
        user_context?: { latitude?: number; longitude?: number };
      },
    ) {
      const url = new URL(`https://api.yelp.com/ai/chat/v2`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago