API Reference

AI Actions

Seamlessly Connect Conversations to SaaS API Functionality

AI Actions for Eucera empower businesses to create dynamic conversational interfaces that seamlessly integrate with SaaS API functionality. By enabling AI-driven actions, users can interact with Eucera’s chat-based UI to trigger API calls, fetch relevant data, and perform automated tasks—all within the conversation.

Adding Action Handlers

Example: Create Task

**Replace createTask with your application functionality and end-point **

eucera.agent("task_management_agent").addActionHandlers({
  createTask: {
      execute: async ({ title, dueDate }) => {
          let task = {};
          // Simulate a network request to create a task
          // In a real-world scenario, you would replace this with an actual API call
          // For example:
          try {
              const res = await fetch('https://api.mock/tasks', {
                  method: 'POST',
                  headers: {
                      'Content-Type': 'application/json'
                  },
                  body: JSON.stringify({
                      title,
                      dueDate
                  })
              });
              const task = await res.json();
          } catch (error) {
              console.error('Error creating task:', error);
          }
          // Simulate a successful response with mock data
          task = {id: 1, title, dueDate };
          return { message: `Task '${title}' created!`, task };
      },
      render: (data, body) => {
          body.innerHTML = `
            <h2>${data.message}</h2>
            <pre>${JSON.stringify(data.task, null, 2)}</pre>
          `;
      }
  }
});

Example: Update Task

eucera.agent('task_management_agent').addActionHandlers({
  updateTask: {
      execute: async ({ taskId, newTitle }) => {
          let task = {};
          // Simulate a network request to update a task
          // In a real-world scenario, you would replace this with an actual API call
          // For example:
          try {
              const res = await fetch(`https://api.mock/tasks/${taskId}`, {
                  method: 'PUT',
                  headers: {
                      'Content-Type': 'application/json'
                  },
                  body: JSON.stringify({
                      title: newTitle
                  })
              });
              const task = await res.json();
          } catch (error) {
              console.error('Error updating task:', error);
          }
          // Simulate a successful update response
          task = { id: taskId, title: newTitle, dueDate: '2023-12-31' };
          return { message: `Task #${taskId} updated!`, task };
      },
      render: (data, body) => {
          body.innerHTML = `
            <p>${data.message}</p>
            <pre>${JSON.stringify(data.task, null, 2)}</pre>
        `;
      }
  }
});

Example: List Tasks using built-in

eucera.agent('task_management_agent').addActionHandlers({
  listTask: {
      execute: async () => {
          let option = [];
          // Simulate a network request to fetch tasks
          // In a real-world scenario, you would replace this with an actual API call
          // For example:
          try {
              const res = await fetch('https://api.mock/tasks');
              const data = await res.json();
              options = data.map(({ id, title }) => ({
                  value: id,
                  label: title
              }));
          } catch (error) {
              console.error('Error fetching tasks:', error);
          }
          // Simulate a successful response with mock data
          options = [ { value: 1, label: 'Task 1' }, { value: 2, label: 'Task 2'  }, { value: 3, label: 'Task 3' } ];
          return { options, label: 'Available Tasks' };
      },
      render: 'EuceraSelect'
  }
});

Example: Delete Task

eucera.agent('task_management_agent').addActionHandlers({
  deleteTask: {
      execute: async ({ taskId }) => {
          // Simulate a network request to delete a task
          // In a real-world scenario, you would replace this with an actual API call
          // For example:
          try {
              const res = await fetch(`https://api.mock/tasks/${taskId}`, {
                  method: 'DELETE',
                  headers: {
                      'Content-Type': 'application/json'
                  }
              });
          } catch (error) {
              console.error('Error deleting task:', error);
          }
          // Simulate a successful deletion response
          return { message: `Task #${taskId} deleted.` };
      },
      render: (data, body) => {
          body.innerHTML = `<strong>${data.message}</strong>`;
      }
  }
});