Script example about notification channel

Hi,

I see something on CLI about notification channel.
But i didn't find clear documentation on which notification we can create per API and the full scope of that function.
is it the Alert function that is available on Genesys Cloud ?
Because even on API document or on Developer tool, there is no real sample about that.

Do you have one ?
Thank you

Hi Matt,

The notification commands follow the same APIs we use for the notification service. I will actually be covering how to watch notifications using the CLI in the devcast today. Here is a preview of the commands today:

//Put this in a file called create-subscription.json
[
       {
         "id": "v2.users.3c57c76a-3e96-424a-a6c1-1706b64bf9dc.activity"
       }
     ]

     //Creates a channel and returns the channel id.  Usually starts with the streaming-as the prefix
     gc notifications channels create
     cat create-subscription.json | gc notifications subscriptions subscribe <<CHANNEL-ID>>
     gc notifications channels listen <<CHANNEL-ID>>

Thanks,
John Carnell
Manager, Developer Engagement

Great !
It works perfectly, thank you.
I was a bit surprise of the content of the json, in fact very simple.

Just a last one.
I'm trying to filter data to show only waiting calls on queue.

I'va got my gc command working perfectly :

gc notifications channels listen streaming-1-ara59sia1835emiptcghf70tll

And i'm adding :

| jq -c '.eventBody.data[].metrics[] | select(.metric == "oWaiting") | .stats.count'

If i copy content of gc command on a file, and filter with

type .\test.json | jq -c '.eventBody.data[].metrics[] | select(.metric == "oWaiting") | .stats.count'

it works.
But the same directly on the command, it don't.

Have you an idea ? is it a streaming problem on powershell ?

Hi Matt,

I don't have a good answer yet so let me play around with the streaming in general and make sure there are no problems there. Once I can confirm in works with Linux, I will take a crack at with Windows and Powershell.

Thanks,
John

Thank you John,

No problem, the main question is : does it works on Linux and on your side.
If yes, the problem is on mine.

But i'm still playing with CLI to check what is possible to. So that's why i'm posting here my questions and limits.

Have a good week end.
Matt

Hi Matt,

No problem. I ran a small test to see if I could do a jq expression against a stream of notifications on a Linux box.

gc notifications channels listen streaming-4-6s0bop18fd4d1uk6bqk6pamp07 | jq -c '.eventBody.routingStatus.status'

I then moved myself on queue and could see the INTERACTING status being printed to the screen. So, I was able to filter on a running stream in Linux. I am going to talk to our internal IT group that manages our internal GenesysCloud instance as they do a boatload of PowerShell and they might be able to help provide an example.

On a side note: I noticed that it is very irritating to get the heartbeats streamed out on the notification when I am streaming data as a single command filter tool like jq tries to parse them. I am going to talk with my team and see if we should provide a flag that will allow you to suppress heartbeat messages or at least write them out to stderr.

Thanks and have a good weekend.
John Carnell
Manager, Developer Engagement

Thanks a lot, so it can works. i will have a look for more test.

I tried, with a simplier jq. not better :
gc notifications channels listen streaming-1-qh0h088okg8uuqda1i7lq0blat | jq -c '.eventBody.group.queueId'

And with a jq -c --stream . But it is a bit more complex, and do not work too.

Hope your team will have an idea :smiley:
Thanks.

Sorry, more test show that :
gc notifications channels listen streaming-1-qh0h088okg8uuqda1i7lq0blat | jq -c '.eventBody.group.queueId'

is working. so i have to go further on in the mastery of jq...
I will post an update when i will find something !

Hi Matt,

Cool. JQ is powerful but can be a little painful at times. Believe me, I have had my own struggles with it :slight_smile: (though I love the tool). If you are willing to share your code snippet when it's done, I would love to put it in our GitHub Recipes repo. I can add it or if you want PR's are welcome.

Thanks,
John

Hi John,

I have tried multiple things, and i really do not manage to get that command works properly...
Will have a look later if i need it, but for the moment seems to be stuck...

Thanks.

Hi everyone,

Does someone have been able to test a jq request on notification in powershell ?
Would be really interesting to have another experience :

gc notifications channels listen streaming-1-ara59sia1835emiptcghf70tll | jq -c '.eventBody.data[].metrics[] | select(.metric == "oWaiting") | .stats.count'

Thank you for your help.

1 Like

Hi Matt,

I think I might have located someone in our Manila team who has done a little bit of Powershell :). I am going to open a ticket with him and see if he can figure out how to do what you are asking with Powershell. I can't guarantee a timeline on when he would even start on it, but I figured I would toss it over to him and see if he could come up with something.

I know we have Powershell needs in our Dev community and I would love to get a few examples of the CLI with it to help serve those.

Thanks,
John Carnell
Manager, Developer Engagement

Sure, great to here that.

Really if i can found a solution on that, i will be happy to create some script because we have some needs.

Have a good day.

Hi Matt,

Are you getting any errors or does it just freeze without outputting anything?
If it's the latter, then are you using Powershell 5 or lower?
If so, that might be the reason. Streaming behaves differently than what you might expect form *nix shells and cmd.

Basically with PS(<=5) it tries to collect the outputs into memory first before piping it but since the external program gc is in a loop standard printing events as they come in, it never gets to the next command (jq)

To get the desired behavior, there are two relatively easy alternatives:

  1. Use the newer PowerShell Core (version 7). This behavior has been fixed for these newer versions and piping the streaming data should work as expected.
    I recommend this approach because installing PowerShell 7 doesn't replace your current PowerShell - it's designed to live with them side by side - So you can use both as you please.

If for some reason, this is not possible in your setup then you can also,

  1. Invoke the good old cmd to run the command inside Powershell.
    This can be as simple as adding this line at the end of your PS script:
cmd /c "gc.exe notifications channels listen $channelId | jq -c "".eventBody.routingStatus.status"""

In this example I have a variable containing the channel Id and a simple jq that gets the routing status of a user. cmd doesn't like single quotes so as you can see I have double double quotes (escaped double quotes) for the jq expression.

Please let us know how it goes.

Regards,

2 Likes

Hi Matt,

Prince didn't mention this, but he does have several examples of PowerShell scripts in our quick hits repo. If you have a chance take a look at it. @PrinceMerluza thanks for putting together these examples.

Thanks,
John Carnell
Manager, Developer Engagement

1 Like

Hi Prince,

Sorry for my long time without answer, i was focus on some other subject.
so to answer.
image
and it just 'freeze' and do not show any filtered answer.

I will try with version 7 and come back to answer.

I just installed PS 7 ;
And It's WORKING !!!

a simple line like that gc notifications channels listen streaming-0-imnrecc0rsnkudkipcg7plofm1 | jq -c '.eventBody.data[].metrics[] | select(.metric == "oWaiting") | .stats.count'

give me waiting calls on queue realtime !!!
Great.
I can play more with that now !

1 Like

Hey Matt,

Keep an eye out on the blog too. Prince just wrote a really nice blog post on Powershell and the gc cli Windows client. We are doing the content review and hope to have it posted in the next couple of days. A lot of the content in the blog post came directly from some of the questions you were asking and Prince doing research on it.

Thanks,
John Carnell
Manager, Developer Engagement

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.