Integrate GitHub Avatar Detection into Your App with zeke/github-avatars Actions

22 Apr 2025
Integrate GitHub Avatar Detection into Your App with zeke/github-avatars Actions

GitHub avatars are an essential part of user identity on the platform. For developers looking to enhance their applications with user profile data, the zeke/github-avatars API provides a straightforward way to determine if a GitHub user has set a custom avatar or is using the default GitHub avatar. This blog post will guide you through using the Cognitive Actions available in this spec, allowing you to integrate avatar detection seamlessly into your applications.

Prerequisites

Before diving into the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Familiarity with JSON data structures.
  • Basic knowledge of making HTTP requests in Python.

Authentication typically involves passing your API key in the headers of your requests to validate your access to the Cognitive Actions.

Cognitive Actions Overview

Detect GitHub Avatar Type

The Detect GitHub Avatar Type action allows you to identify whether a GitHub user has set a custom avatar or is utilizing GitHub's default avatar. This action falls under the image-processing category.

Input

The input schema requires a username, which is the GitHub account identifier. Below is the required structure:

  • username (string, required): The GitHub username of the individual or organization. This field is necessary to identify the GitHub account associated with the request.

Example Input:

{
  "username": "zeke"
}

Output

Upon successful execution, the action returns a JSON object containing the following fields:

  • href (string): The URL of the avatar image.
  • username (string): The GitHub username that was queried.
  • prediction (string): Indicates whether the avatar is "custom" or "default".

Example Output:

{
  "href": "https://github.com/zeke.png",
  "username": "zeke",
  "prediction": "custom"
}

Conceptual Usage Example (Python)

Here’s how you might call the Detect GitHub Avatar Type action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "840f1c33-4909-49f2-8a9e-1b03125377c6"  # Action ID for Detect GitHub Avatar Type

# Construct the input payload based on the action's requirements
payload = {
    "username": "zeke"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload variable is structured according to the input schema, ensuring that the username is correctly sent to the API. The response is processed to print the result or any error messages.

Conclusion

The zeke/github-avatars Cognitive Actions provide an efficient way to integrate GitHub avatar detection directly into your applications. By leveraging the Detect GitHub Avatar Type action, developers can enhance user interfaces and personalize user experiences based on avatar information. Consider exploring further use cases, such as integrating this functionality into user profiles or social features in your applications. Happy coding!