And now it's a bigger deal.
We're going to hook up the output of the agent to send messages back to telegram.
How are we going to do this?
We'll start by taking the putting the power back on again of this, of this node and double click so
that we're looking at this node.
And remember we need to fill in a chat ID and text to send the message back to telegram and to give
it the right chat ID.
So it comes back to the person that asked the question.
That's the final part of hooking up our integration.
Let's start with text.
So you can see over to the right here that there's this toggle between fixed and expression.
And this is the key.
This is where we choose between always posting a fixed bit of text like bananas and just that always
being the response in telegram.
We don't want to do that.
We want it to be something that is populated based on what has come in from the AI.
So what's come in from the AI?
Well, it's written over here, it's JSON, it's look, it's this, this, this list of the single thing
here, this object and that object has a single key value pair.
A key is output and the value is.
Hello.
How can I assist you today?
That's what we want.
We want that.
So how do we do this.
Well it's it's just a matter of clicking on expression.
We want an expression.
Have a think about.
If you think of the expression we would want how do you describe expressions.
It's with two sets of curly braces.
If you type two opens it does two closes for you automatically.
We have it.
We have to type an expression in there.
It's already suggesting what we want.
And partly we want to start with dollar JSON, which means the JSON object that's coming in okay.
And now that dollar JSON, it has a single field called output.
That's what we want.
So we type dot output.
And when we type that you can see in the result it tells you it gives you this hint.
This is what it would be.
Hello.
How can I assist you today.
That's perfect.
That's what we want.
And so just by clicking here you can see I have now hooked it up so that the text that goes back to
telegram is the output field from here.
Perfect.
There is an easier way of doing this.
You probably guessed this.
I didn't need to type that in there.
I can actually take this drag and drop it in there and it does it for me.
But I did want you to have complete understanding of what's going in there and why, to make sure that
the output of the data that's coming in is what will be passed in to telegram.
Okay, now it's time for chat ID, and this one is a little bit more tricky.
Click in chat ID again, we can just type in a fixed chat ID we don't want that.
We want it to be an expression.
Okay so we want the chat ID where are we going to find the chat ID.
Well the chat ID is something that we would expect to be coming in at the beginning from telegram.
So we really want to we want to pluck something out of the data that came in at the very start.
If you come over here, you'll see that in this this field of incoming data, there is a drop down here.
And this drop down is where you can select other nodes in this workflow that might have data associated
with them.
Okay.
Go to the drop down and select the telegram trigger which is two nodes back.
If anything has the information about this telegram chat it will be the telegram trigger.
Let's select it.
This is the data that came from the telegram trigger in JSON.
Let's look at this.
There's a message ID there's a chat.
There's a chat ID.
Well, that seems like something that belongs right there, right.
Okay.
Wouldn't it be nice?
Wouldn't it be nice if you could just select expression here and then you could just go here, click
and hold down and drag that to chat ID and let go.
Wouldn't it be nice.
It is nice.
That's exactly what you can do.
And if you take a look at this, whilst you might not have been able to write it yourself first time
since we we covered some of this before.
Hopefully you have intuition as to what this is doing.
It's taking the telegram trigger node.
This is actually a shorthand for that, that dollar node thing I showed you before.
So it's taking the telegram trigger node and it's taking item message chat ID it's drilling all the
way down to here.
But you don't need to know how to write this yourself because you can always drag and drop.
It's so simple okay.
And you can see down there it gives the results and you can see that that seems to match.
That's cool.
All right.
Let's, uh, let's go back and see if we can't give this thing a whirl.
Okay.
So first up I'm going to press Execute Workflow which sets the thing running waiting for a trigger event.
All right.
Let's bring Telegram's window over here.
Move it to the side.
And I'm going to say uh.
Hi there.
Uh, what's two plus two that started off light.
Uh, and let it do its thing.
Everything is running high.
Two plus two equals four.
How can I assist you further?
Wow, that just worked.
We just had the workflow happening.
We were just able to get a chat to run.
We were able to bring in the information from the telegram trigger.
We were able to process it in an AI agent.
We're able to send the message back.
And because of the way we hooked up the data, the message that came from the AI agent was was sent
back to telegram, and the chat ID linked it with the incoming message such that the response appeared
here in the telegram window.
That's fabulous.
Now, I mentioned there's one more little fiddly thing, the simple memory here.
It has a problem because it needs to have a session key, some key to tell it uniquely how to identify
this conversation.
And it's it's, uh, initially defaults to this because it thinks it's connected to a chat trigger,
and that's not going to work.
Okay.
So we really want something that is somehow going to give it some memory associated with this particular
chat.
Do we have anything like that?
Well, maybe we do.
So let's first of all click here and say define below so that we can give ourselves an expression.
In this key we're going to click expression so we can have anything we want in there.
And let's take the chat ID.
Let's drop that in there.
And now we are hooking up this memory to this particular chat ID.
That seems like it's common sense.
All right.
Let's give this a whirl.
All right.
Back I've come to the workflow and I've made sure that the simple memory is is is activated again.
It was turned off.
We turned it on.
Uh, and, uh, we will press the execute workflow button.
I'm going to come over here and I'm going to say hi there.
My name is Ed.
I'll let it do its thing.
Hi Ed.
Nice to meet you.
How can I assist you today?
And I'll say what's my name?
And I'll press execute workflow again.
Move that out here.
Execute workflow again.
And here we go.
Your name is Ed.
How may I assist you further?
So there we have it.
It works.
The memory is there, and you can experiment with smarter ways of doing this.
So you.
If we look in this memory, you can see that we attached it to this chat ID, which might make sense,
but you could also attach it instead to the username, the telegram username.
And that way the memory will persist between different chat sessions with the same telegram user.
And that might be even better.
So you should experiment with that.
Okay, so we have just built a two way integration with telegram.
We have it so that telegram, when messages are sent it gets triggered.
And we are then able to respond.
And those responses get posted back to telegram in the same chat ID.
And we have memory that's attached to that chat ID as it happens as of now.
And it's all working.
There's one more little thing, a little wrinkle in here, which is the way we keep having to press
the execute workflow button, which is kind of annoying every time that we want to respond to suck something
out of telegram, we can't be doing that.
That doesn't feel very automated, does it?
Okay.
It's time for us to publish our first workflow.
Everything we've been doing up to this point has been in test mode.
We've built a workflow, and then we've pressed the Execute workflow button.
That means we're testing it and we've seen the different the boxes light up as they run.
That's not the way that you finally deliver an NM workflow when you've finished it.
The way you deliver it is by pressing the publish button, so we'll save it first.
When you publish it.
This whole workflow goes live as like a running thing in the world, and you won't see boxes highlight
anymore because it will just all be running.
Let's give it a whirl.
We're going to press the publish button.
It wants a version name.
You can give it whatever you want and describe the changes.
We press publish and it says the workflow is now published, it will listen for events from telegram.
Got it.
Okay, uh, let's let's give this a try.
Let's actually message our workflow running in production.
All right, here we go.
Let's start by saying hi there.
Hello, editor.
Sorry I closed down the bot father here.
Uh.
Hello, editor.
How can I help you today?
Uh.
All right, um, what's the current date?
See how it does.
We're hoping that the tool is being called.
The current date is.
And yes, that does indeed appear to be the current date for me.
Hopefully you will have a different date.
December the 15th.
It worked.
This is running.
We have a telegram connectivity both ways and using a tool.
And we've deployed it.
We've published it.
This is running live.
No longer do we see the boxes lighting up because we're not testing.
This is running in production.
And so you should now do this.
If.
If you have telegram, then you should hook up.
You should make the trigger.
You should send the text message and then have a tool that you like.
And then press publish and try this out so that you can have your first deployed workflow running.
Congratulations.
That's that's a much more meaty integration.
And now at this point, uh, go to this triple dots up here and select Unpublish to stop it from being
published and unpublished.
There we go.
Unpublished successfully.
That is done.
You can give it a nice name telegram workflow up at the top by clicking there, and then press save
and then go back and we'll see.
The telegram workflow is completed.
So we've talked a lot of boxes, a more in-depth integration and publishing to production.
It's now time for the final integration of today.
And I tell you, if you thought this one was a little bit grueling, the next one is more grueling.
It's time for slack.