send custom notifications via ftrack_api
3 3

9 posts in this topic

Hi all,

is it possible to send custom notifications via ftrack_api?

We are automating a lot with actions. But this creates also a lot of confusion. We need to communicate better to the users. We are using the pop up messages, but these are displayed only for 5 seconds. Sometimes the user is missing them, sometimes the message is going away before he/she finishes reading it.

Sending notifications to the user will help a lot in understanding what is happening.

Share this post


Link to post
Share on other sites

Hi Remus, this could be done in two other ways at the moment:

  • Trigger an action dialog for the user with the information. You can just use label with markdown to get the message through.
  • Create a job to show the user progress.

As for the notification system we have ideas of revamping the notifications and at the same time give the ability to add your own. Note that this is just internal discussions at the moment.

Share this post


Link to post
Share on other sites
Quote

Trigger an action dialog for the user with the information. You can just use label with markdown to get the message through.

Could you elaborate on this?

Trying to trigger an action dialog from a custom published event, and can't seem to get it to work.

Share this post


Link to post
Share on other sites

Hey Mattias,

Tried getting the examples running, but couldn't so wanted to see if you could correct my example code?

import getpass

import ftrack_api


def callback(event):
    """Status change updates."""

    session = ftrack_api.Session()

    for entity_data in event["data"].get("entities", []):

        if entity_data["action"] != "update":
            continue

        if "statusid" not in entity_data["keys"]:
            continue

        new_status = session.get(
            "Status", entity_data["changes"]["statusid"]["new"]
        )

        # Task changes
        if entity_data["entityType"] == "task":
            if new_status["name"] == "In Progress":
                event = ftrack_api.event.base.Event(
                    topic='ftrack.action.trigger-user-interface',
                    data={
                        'type': 'form',
                        'items': [
                            {
                                'label': 'My Boolean',
                                'name': 'my_boolean',
                                'value': True,
                                'type': 'boolean'
                            }
                        ],
                        'title': 'Foobar'
                    },
                    target=(
                        'applicationId=ftrack.client.web and '
                        'user.id={0}'.format(
                            event['source']['user']['id']
                        )
                    )
                )
                session.event_hub.publish(event)

    session.commit()


def register(session, **kw):
    """Register event listener."""

    # Validate that session is an instance of ftrack_api.Session. If not,
    # assume that register is being called from an incompatible API
    # and return without doing anything.
    if not isinstance(session, ftrack_api.Session):
        # Exit to avoid registering this plugin again.
        return

    # Register the event handler
    subscription = (
        "topic=ftrack.update and source.applicationId=ftrack.client.web and "
        "source.user.username={0}".format(getpass.getuser())
    )
    session.event_hub.subscribe(subscription, callback)

When a task's status is set to "In Progress" this code should show a form for the user to interact with.

Share this post


Link to post
Share on other sites

Thanks Mattias :)

I've used the shared session from ftrack-connect, and that works well.

Now the question is how do you intercept the "Submit" event?
Normally you look for "values" in the same event.

Share this post


Link to post
Share on other sites

Should have investigated it deeper. The event from hitting "Submit" on the dialog has a topic of "ftrack.action.launch" with the values in it.

Might be nice to update the documentation with this information.

 

import getpass

import ftrack_api
from ftrack_connect.session import get_shared_session


def callback(event):
    """Status change updates."""

    session = get_shared_session()

    for entity_data in event["data"].get("entities", []):

        if entity_data["action"] != "update":
            continue

        if "statusid" not in entity_data["keys"]:
            continue

        new_status = session.get(
            "Status", entity_data["changes"]["statusid"]["new"]
        )

        # Task changes
        if entity_data["entityType"] == "task":
            if new_status["name"] == "In Progress":
                event = ftrack_api.event.base.Event(
                    topic='ftrack.action.trigger-user-interface',
                    data={
                        'type': 'form',
                        'items': [
                            {
                                'label': 'My Boolean',
                                'name': 'my_boolean',
                                'value': True,
                                'type': 'boolean'
                            }
                        ],
                        'title': 'Foobar'
                    },
                    target=(
                        'applicationId=ftrack.client.web and '
                        'user.id={0}'.format(
                            event['source']['user']['id']
                        )
                    )
                )
                session.event_hub.publish(event)

    session.commit()


def action_launch(event):

    print event


def register(session, **kw):
    """Register event listener."""

    # Validate that session is an instance of ftrack_api.Session. If not,
    # assume that register is being called from an incompatible API
    # and return without doing anything.
    if not isinstance(session, ftrack_api.Session):
        # Exit to avoid registering this plugin again.
        return

    # Register the event handler
    subscription = (
        "topic=ftrack.update and source.applicationId=ftrack.client.web and "
        "source.user.username={0}".format(getpass.getuser())
    )
    session.event_hub.subscribe(subscription, callback)

    subscription = (
        "topic=ftrack.action.launch and "
        "source.user.username={0}".format(getpass.getuser())
    )
    session.event_hub.subscribe(subscription, action_launch)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
3 3