Skip to content

API call works on localhost but not on app integrations #2983

@Jeezman

Description

@Jeezman

I've been unable to get my api calls to work when the route is triggered on app integrations.
Currently have Telegram, Whatsapp and Webchat integrated but I get no response from the bot on.

It only works on localhost.

Here's my code snippet

import { Button, Text } from '@botonic/react';
import React from 'react';
import fetch from 'isomorphic-fetch';

const createInvoice = async (memo: string) => {
  try {
    const url = 'https://app.io/api/v1/payments';
    const response = await fetch(url, {
      url,
      method: 'POST',
      headers: {
        'X-Api-Key': 'xxx',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        out: false,
        amount: 500,
        memo: memo,
      }),
    });

    const data = await response.json();
    if (!response.ok) {
      throw new Error(data.message || 'Payment failed');
    }

    return data;
  } catch (error) {
    console.error('Lightning payment failed:', error);
    throw error;
  }
};

export default class extends React.Component {
  static async botonicInit(request) {
    const question = request.input.data;
    const username = request.session.user.username;

    let memo = `invoice created by ${username}`;

    let invoice = await createInvoice(memo);

    console.log('invoice is ', invoice);

    return { question, invoice };
  }

  render() {
    return (
      <>
        <Text>Question is {this.props.question}</Text>
        <Text>Please make pament to:</Text>
        <Text>{this.props.invoice.payment_request}</Text>
      </>
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions