# Creating a StoryTelling Action in Google Assistant — Part 2

Photo by [Thomas Kolnowski](https://unsplash.com/@tkolnowski?utm_source=medium&utm_medium=referral) on [Unsplash](https://unsplash.com?utm_source=medium&utm_medium=referral)

Welcome back to Part 2 of storytelling action in google assistant. If you are new have a look at Part 1 of creation dialog flow for storytelling action.

Let’s create the backend part for our storytelling action using firebase cloud function.

Folder structure for the storytelling action would be like this

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055540495/df44fdb9-1127-42fa-a3fe-3f6f5d095184.png align="left")

We will import the dialog flow module and response creation dependencies

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055542087/65644577-f65e-425f-b3e6-33ad4357ec33.png align="left")

We will add the code for the welcome intent

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055544056/8d6b6463-a979-40c2-b5c7-48a9449f19ff.png align="left")

Whenever the action is opened it will show the title and fetch the stories

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055546538/3fc28e9d-6c28-4fc1-a6fd-daf5371dd232.png align="left")

We have written a logic to shuffle the stories each time when the user opens the action

We have kept the stories in a separate file named [stories.js](https://gist.github.com/nidhinkumar06/7272a7bf477ea5045146c8c640e68595)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055548294/8bbf6ee9-45a4-40bc-95a1-e013986ff5fa.png align="left")

To show the stories in carousel effect

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055550277/9e26af30-2ac9-4f82-be16-18ade9a99b6a.png align="left")

We have handled for both cases that are displaying the action in the smartphone as well as in smart speakers

Once the user selects a story it will be passed to the media object

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055551993/f8d768f8-f212-40f0-8187-4e01278d389f.png align="left")

Where it will start to play the mp3 file

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055553861/1bce40ad-f5a3-48de-a49f-128492c4f3f6.png align="left")

Once the media object gets started to play we can stop the audio for that we need to handle the media response

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055555208/871c6b48-ad0f-4642-8189-cc70e2ddac45.png align="left")

If the user says yes or no we should handle the case using the below intent

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055557518/576966d8-4c5a-4698-811a-1efebe210191.png align="left")

If there is no response from the user means

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055559588/6e19fa94-2966-4605-8b6b-3a171dcaab94.png align="left")

We have linked all the intents we created in the dialog flow and it’s time to deploy our function to firebase using the command

firebase deploy

once deployed copy the URL and go to dialog flow

Click fulfillments and paste the URL in webhook

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055561423/db7cc297-ca7e-4045-9fdf-09b99f69bee5.jpeg align="left")

Click save

Now it’s time for testing your action

The end output would be like

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055562818/7b8bfa4a-944f-4885-9d7f-2104ea8b3d5b.jpeg align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1698055564207/01f8e084-38f5-4a02-8bdb-d023ce880002.jpeg align="left")

Congratulations you have created an action in dialog flow using firebase go ahead and publish your action

Cartoon Stories — [Find out the skill in google assistant](https://assistant.google.com/services/a/uid/0000004bc2afdf91?hl=en_in&source=web)

Here are the gist files for the storytelling actions

[index.js](https://gist.github.com/nidhinkumar06/c49e16d824b37e5f13c72a32604b7f6e)

[storyAudio.js](https://gist.github.com/nidhinkumar06/f6cd3c50aaeedbb7eab6aee0857cceb9)

[stories.js](https://gist.github.com/nidhinkumar06/7272a7bf477ea5045146c8c640e68595)
