OK, but we mentioned that we wanted
to display this joke in a Power App.
So let's go into the Power App
Dashboard and in order to connect
the Power App to an Azure function
there's there's many choices, but we're
going to go through the simplest one,
which is creating a custom connector.
And here, I'm going to click
create from blank.
I'm going to give it the name API jokes,
and now you'll know how many dry runs
I've done more or less.
So API jokes eight, click continue.
Then we're going to upload a picture.
I want to make sure that I include
a picture that allows me to quickly
identify my own custom connector,
and then it's going to ask for my host,
which is jokesapi.azurewebsites.net
and then our base URL is API.
The next option that we have
available here in our custom
connector is the authentication type.
And remember we chose Anonymous
for our function,
but of course you can use
different types of authentication,
so if your function uses a security code,
or maybe if you need to use OAuth 2.0,
you can definitely use that in
your custom connectors as well.
Let's move on to the definition we want
to add a new action and this is where
we actually call the function method.
So let's call this generate joke and
then the operation ID is the same.
And our request will be a get method
at this particular URL which I've
mentioned many times already.
We're importing that to define the
schema of our request and then
we want to define the schema for
our response as well.
So instead of defining it manually,
I'm actually going to import it from samples
So what I'll do is copy this long joke
that has been created here for us and then
import that and I will generate
a very simple pattern
here I'm going to create connector.
And
again,
as I mentioned,
this is one of the simplest ways
of creating custom connectors.
My colleague Justin will actually
have a talk later on that will give
you more advanced use cases and I
highly recommend you you come back
for that for his talk and there's
a few other folks that are talking
about serverless and custom connectors
and more advanced use cases,
so please stay tuned and check
out those talks as well.
OK, now I'm going to go into test.
And this is where I'm going to have to
create a connection to our function app,
which is just as simple as clicking create
and our connection is now available.
So, yay, we are ready to create a new app.
We're going to create a new canvas app
from blank, let's call it DethAI, right?
That's Donna and Seth, DethAI
Does that work?
I hope so.
Ok, so creating a new Power App and
this is going to be the simplest Power
App that you will have ever seen.
It's literally just a screen
with a button and a text.
When we click the button we'll call
the function app and when the response
comes back we're going to show that
response into the texts right here.
So let's go ahead and insert a button.
And of course you can create more
complicated UI's with the Power App as
complicated as you want them to be,
but in this case,
let's keep it simple.
Let's rename this as get
joke and then also add our label.
We want to make this bigger in
case our joke is a large one.
So in this get joke on select we want
to use the clear collect method which
brings us the data from the from the
API and we want to save that data
into a response collection and then
we want to call the function API.
But hey, we haven't actually connected
our Power App to our custom connector,
so let's go into the Power
Apps data option here.
And in our connectors you can
see that we will find here API.
One second. So we have API jokes eight.
We want to add that connection.
We want to click Connect.
And immediately our function
will become available here.
So if I
start typing API jokes,
it will already autocomplete to
generate joke and then bam, this
is our API call and then when
we go back to our label instead
of displaying hardcoded text,
we want to display our response.
And actually we want to get the
the first element of our response.
One second, just here,
and then we want to retrieve the joke
property or display the joke property.
OK cool, so if everything
is connected correctly,
our applications should run.
And it would it would retrieve the next joke.
So the way I'm going to test
this, you can either
click preview the app here,
so that's what I'm going to do
and then click get joke and this
is loading it's loading and now
we're getting ready for the best
AI generated joke ever. In a bit.
Well that is not working out correctly.
So DethAI is punished right now.
What do you call a pretty cow
on a book for the first time
I don't know
my shoes. That is so random.
But hey, it works.
The other thing that will be your
homework for next time that we
meet is actually going into Power,
automate and create a flow that will
use the exact same API an it will
instead of displaying it in a Power App,
what we want to do is actually
send that as a message using the
Twilio API so you can see here that
I've already created this stateful
orchestration that runs every minute.
Or every week or every day,
depending how on how often you
want this to be displayed,
and then it makes an HTTP call.
It parses that JSON and it sends
the text message to a phone
number that you've just chosen.
So this is your homework.
You have to send me a message
with AI generated jokes.