How To Create Chat Space with Google Sheets Apps Scripts

Learn how to create chat spaces in Google Sheets using Apps Script, enabling you to assign tasks to team members seamlessly. This tutorial covers the necessary steps and code to automate chat space creation for efficient collaboration.

So there's this really cool video I saw in Google Workspace that allowed you to assign tasks to other people. Now, usually Google tasks is only for myself. I can assign myself tasks, but Google Workspace says, Hey, here's a couple buttons you can do to assign someone else a task. The key is you need to create a chat space. You need to have them in the same chat space as you. And you can assign people in that chat space some task, it'll show up on their ta. Google tasks. It's actually really cool because it allows you to just like send something to someone. Then when they click yes, they've done it, you get notified. It's really, really awesome. I love it. But here's the thing. We need to create chat spaces with people that we want to do this with.

And sometimes if you're like, Hey. Th this is a new thing we gotta do. We, you wanna set up a bunch of chat spaces and you don't want to have to go to Gmail or chat.google.com. Go to spaces, click create a space, type in the name new one, new chat here with Bobby and Kathy. You don't wanna have to do that, right? Like. Yeah, you want to just get this create, click, create. Oh yeah. Allow external members to join, but you just wanna create these spaces and, and be done with it. Right? And then you can come in here, add members, do all that stuff. I'm gonna show you a pro programmatically slash in abs script. How to create a new space. It's fairly simple, but we got a few steps to do.

Go up to extensions app script . Right now it's blank for me, but I'm gonna add a few things we need to do. We need to add Google Chat in chat services. We need to add it in OAuth scopes. We need to create a Google project. We need an OAuth screen. We need to enable Google Chat, API, and we need to have external chat settings. It's on okay. All of these steps I'm gonna show you. You just need to know where to click, honestly. You just need to know where to click, where to put this information. I'm gonna show you. And then at the end of this we'll have the, the code will work, so we'll call it function , create space, and it's like two lines of code. We're gonna have chat dot spaces create, and we're gonna create a space here.

We can get the name of this, so we'll say like variable chat name equals this, and then we will maybe like append all, let's create spaces and we'll append it here. We'll go spreadsheet app, get active spreadsheet , get sheet by name spaces. Append row. And here in square brackets we'll append this check name so we know it was created. Boom, right there. Maybe we will get also the space name. We'll get the name. The display name will add as a variable display name equals here, like something and so we'll take this display name and add it here as well.

Just copy paste. So we need to use this chat dot spaces. Create, create a space while variable space equals we need curly brackets. And we're gonna add some information here. First, we're gonna have display name colon, and we'll put the display name here. So this is actually the JSON that we need to send. We need to have a space type, and that's just gonna be the word space in quotes. Literally what kind of space it is is a space. External user allowed and we just set that to true. And then we need some space details and in curly brackets as well. We'll add a description and we might have this description. We can enter that later as some text or some variable if we want to.

Okay, so all of this now will create a space called something. However, I need to go up and I need to do all of these things. So I'm gonna save this script as is, and I'm gonna go over to the left side of services here, add this on the plus sign and go to, scroll down to Google Chat, API select it and click add. It will say adding service, and you'll see it listed over here on the left side. So we have done that so far. Now we need to add this URL in OAuth scopes in app script . Over on the left side, there's project settings, show app, script dot js, ON go to editor . It's now a file here. And over down on the bottom after runtime version at a comma, at OAuth scopes

colon and in square brackets, in quotes, put this, actually, I think the A is not capitalized. It's just otoscopes That's. What we need to have. So back to our code. We have now added this to our OAuth scopes in App Script . Now we need to add a Google project with a number . This is actually fairly difficult, but I'm just gonna show you the steps. Go back to our project settings. Scroll down and you'll see Google Cloud Platform Project Change Project. We need a number . Okay, you need to go to console.google, sorry. console.cloud.google.com and make sure you are in the exact same account as. Your sheet that's very important to be in the same account. We're gonna go to new project. We're gonna create a new project called Chat Space Billing account.

It's all free. Just create, once it's created, you'll need to go to that project. So select project. Make sure you are in the correct project that you just created. At the top it says Open Project Picker. It says Chat Space. I know I'm in the correct account. Or project on the left side there's project info. I dunno if I can zoom in that much, but I just copy that project number and I go back to my app script and paste it there and set project. I'm gonna need to do one quote unquote big step, but I'm gonna show you all the few clicks you need to do OAuth consent details. You can click here. But if you have multiple accounts like I do, I need to go to it. So I need to go to the dashboard . I need to go over to the left side.

API services, a wealth consent screen. I need to click get Started, app name chat space, my email next internal. This will allow you to just get this done. Just a few clicks. You do not need to do any authorization . Click next. Put my email address. Click next. Yes, I agree. Click continue and create. After a bit of processing, it'll take tell you at the very bottom, Ohau configuration created. Yay. Go back to our Project Set. Project. Perfect. It's working. Okay. Let's go back to our editor . We have added our Google project with number . Yay. We have a consent screen. Yes. Alright, now let's enable Google Chat, API in back in our console cloud.

We need to enable the Google chat, API go back to our console, dot cloud.google over on the left side. You'll see the menu go to APIs and services, enabled APIs and services. And if you've just created this project, you won't have anything, but you'll have a button up at the top blue button that says, enable APIs and services. Click that we need Google Chat. Search for it. Google Chat, API, click it. Click enable. And let's do this last thing 'cause we have just enabled it. We need to go to admin console apps, Google Workspace, Google Chat. So this is a different area. It's called admin.google.com, and we go over to the left side, go to apps. We need to go to Google Workspace. We need to find Google Chat and scroll down and see external chat settings. And make sure it's set to on. And this only applies to users with, in my case, Google Workspace

Business Standard License. This may not be. Available for every single user of every single account on Google. But the point is that if you want to keep your chat spaces to only your domain, okay, you don't have to do this, but if you are like dealing with freelancers or dealing with clients, and you want to create chat spaces with external people outside of your domain, you need to click this on. So not everybody needs to do this, but it's very useful for those who do need to. Okay, we have done that. So let's see if this works. We're gonna save everything. We have our two or three lines of code, and we're gonna come in here and say, create space or run. We'll have to authorize the very first time we do it. It says, we have not turned the Google Chat app on.

The, let's go double check that console, dot cloud.google.com. APIs and services enabled APIs and services Dozen doesn't look like I. Google Chat, API manage looks enabled. Let's create credentials, web application, name, chat, space creator, and create. I'm just gonna name the, this. I guess we haven't gone here. So console.cloud.google.com. Go to your Google chat, API In these four tabs, there's credentials and then there's configuration. We need to add an app name, chat creator. We need a URL of an avatar. I am gonna use mine from better sheets. We need to connection settings , app script . We just want HT P endpoint, URL, I think. We can disable those. We just need to create this. Just click save. So we have a configuration.

Now we'll go back to our script. We'll try again. We need to add one more thing to our app script . Jsun, add another comma. Here we go. So we need. Both the chat spaces and spreadsheets safe. Let's run it again. We got permissions. This a good, this is a good sign. Let's click continue. It says it's completed. Let's go back to our sheet and yes, we have some data here. Great. That's all of our data type space. It's a whole bunch of stuff. And then the name. So let's go back to our chats. There it is. There's something, actually, I have two. Okay. Let's create a new one. I want to, we, let's select from here, like this is the name a two.

So instead of this something as in hardcoded, we'll do spreadsheet app, get active spreadsheet , get active range , get value. So wherever we are, we're going to select this, create space. But how do we do that? Let's go to the top and add a custom menu at bitter sheets.co/snippets. We can grab this code very easily. We just need to find the custom menu . Here it is, and we paste that here and we'll say Create space, chat space. And then we select this create space function as this second item here. Save this now when I close this and go back to my sheet and refresh my sheet. I will see up at the top. There's extensions, help, accessibility and custom menu create space.

So I'll take this new chat space. I'll select this function . It's done it. There it is. New chat space. Perfect. Now I'll create marketing, custom create chat space. Perfect. It's doing it. It's creating them, giving us all this information. Cool information here. The name here. Awesome. We can actually pick out this information like Wes a space URI Here. Let's grab that. So instead of chat name, this is just chat info. We'll say chat info and then we'll do.space URI save. Let's go back and create a new one. Google Ads. Custom menu . Create space. And there we are. We have a URL to the space we created.

We have the name of, the name of the space. Very cool, right? This is all we had to do. Whole bunch of cool stuff, but really, really, really awesome to be able to do this inside of App Script with just a few lines of code and knowing where to click everywhere along the way. The last part, the admin console, apps, external settings, doesn't need to be for everyone. If you don't want external chat settings on, but if you do, that's very important. You gotta go to admin console apps, Google Workspace, Google Chat, then go to scroll down to external chat settings and it must be set to on if you want to have that. Cool. Thanks for watching. You are watching better sheets here on YouTube. Make sure you check out this video or this video and subscribe right

now to get more tips, tricks, how tos, get more out of your Google sheets than you ever have before. I'm excited to be making a ton more videos here. Ask me questions down in the comments and I will answer them in future videos. But for right now, right here, one of these videos is gonna be your next Google sheet.