FeedbackPRO

f10.dev
Search Results for

    Creating Integrations

    All integrations must contain two components: API and Configuration. All official integrations also include a Settings Provider to display configuration settings inside Project Settings and to streamline the creation of config instances inside FeedbackSettings. Their use is highly recommended, but is not required to integrate a service.

    This section will use a fictional third-party service integration as an example on how to setup custom integrations.

    API

    This component is tasked with communicating with the chosen service to integrate, including status checks, authentication and FeedbackData formatting and sending.

    All API components must derive from the FeedbackAPI abstract class. For an in-depth view of all available options, check the Scripting API section.

    The following example is a simple API integration that uses a WWWForm for requests:

    public class MyAPI : FeedbackAPI {
      private const string UploadEndpoint = "upload";
    
      protected override string BaseUrl => "https://myapi.example.com/api";
      protected override string StatusEndpoint => "status";
      protected override Dictionary<string, string> Headers => new Dictionary<string, string> {{ "Header", "Header_Content" }};
    
      public override async Task<bool> Send(FeedbackData data) {
        var desc = data.Summary;
    
        foreach (var section in data.Sections) {
          desc += $"\n{section.Title}\n{section.GetData()}";
        }
    
        var form = new WWWForm();
        form.AddField("title", data.Title);
        form.AddField("summary", desc);
        form.AddField("date", data.Date.ToString());
        foreach (var file in data.Files) {
          var (fileName, fileData) = await file.GetFileAsync();
          if (fileData == null) continue;
          form.AddBinaryData("file", fileData, fileName);
        }
    
        var uwr = GeneratePostRequest(UploadEndpoint, form);
        var success = await uwr.SendWebRequest();
    
        if (!success) {
          return false;
        }
    
        uwr.Dispose();
        return true;
      }
    }
    
    Note

    The base class FeedbackAPI contains multiple helper methods for generating configured requests (GET, PUT, POST, etc.) supporting multiple data types (WWForm, JSON, etc.). Check the Scripting API section for more information.

    Configuration

    This component is tasked with storing any values that may be used or required by the third-party API (authentication, versioning, etc.) and generating API instances.

    All configuration components must derive from the IFeedbackConfig interface, and must be marked as Serializable. For an in-depth view of all available options, check the Scripting API section.

    The following example is a simple config meant to be used with the previous API example:

    [Serializable]
    public class MyConfig : IFeedbackConfig {
      [SerializeField]
      private bool _active = true;
    
      [SerializeField]
      private string _exampleValue;
    
      public string ExampleValue {
        get => _exampleValue;
        set => _exampleValue = value;
      }
    
      public string IntegrationName => "My API";
    
      public bool Active => _active;
    
      public FeedbackAPI GenerateApi() {
        return new MyAPI();
      }
    }
    

    Settings Provider

    This component is tasked with displaying the integration's config values and facilitating the creation and management of config instances, along other helper methods.

    Settings provider components must be static classes and part of the Editor assembly. The included SettingsProviderHelper facilitates generating an instance of a SettingsProvider in the correct location, with the correct parameters. For an in-depth view of all available options, check the Scripting API section.

    The following example is a simple settings provider meant to be used with the previous config example:

    public static class ExampleSettingsProvider {
      private static bool? _integrationStatus = null;
    
      [SettingsProvider]
      private static SettingsProvider CreateSettingsProvider() {
        return SettingsProviderHelper.GetProvider<MyConfig>(PreferencesGUI, ResetConnection, "My API Integration", new[] { "my" });
      }
    
      private static void PreferencesGUI(SerializedObject settings, SerializedProperty serializedConfig, MyConfig config) {
        Styles.DrawHeader("This is a Header", "This is a tooltip");
    
        EditorGUILayout.PropertyField(serializedConfig.FindPropertyRelative("_exampleValue"), new GUIContent("Example Value"));
        EditorGUILayout.Space();
    
        SettingsProviderHelper.DrawCheckStatusButton(config, _integrationStatus, result => { _integrationStatus = result; });
      }
    
      private static void ResetConnection() {
        _integrationStatus = null;
      }
    }
    

    Enabling A Custom Integration

    If the custom integration uses a Settings Provider, a new settings menu should appear under FeedbackPRO's setting menu inside Project Settings. Displaying this menu should create a new config instance, therefore displaying it as an available integration in the main settings screen, along all the other installed integrations.

    If no Settings Provider has been created, a new config instance must be generated before it can be displayed as an available integration, or data must be manually sent to the integration directly, as Feedback.Send() will not be able to find the integration as active.

    In this case, to generate a new config in the FeedbackSettings file, the following code must be executed at least once:

    FeedbackSettings.GetConfig<MyConfig>();
    
    Note

    Official integrations use the exact same API's available and documented here. Since the core package and all integrations are distributed "Open-Source" (not under any DLL or obfuscation) custom integrations can be created with the same design and functionality as official ones, although with a higher level of difficulty.

    In This Article
    Back to top

    FeedbackPRO v1.0.2 rev 5

    Generated by DocFX