Skip to content

Commit 8102759

Browse files
PierrickVouletpierrick
andauthored
feat: update GAPIC samples to be featured in create message guide (googleworkspace#482)
* feat: update GAPIC samples to be featured in create message guide * Fix style --------- Co-authored-by: pierrick <[email protected]>
1 parent 847e2aa commit 8102759

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

chat/advanced-service/Main.gs

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -91,41 +91,47 @@ function createMessageAppCred() {
9191
// TODO(developer): Replace SPACE_NAME here.
9292
const parent = 'spaces/SPACE_NAME';
9393
const message = {
94-
text: 'Hello with app credential!'
95-
};
96-
const parameters = {};
97-
98-
// Make the request
99-
const response = Chat.Spaces.Messages.create(
100-
message, parent, parameters, getHeaderWithAppCredentials()
101-
);
102-
103-
// Handle the response
104-
console.log(response);
105-
}
106-
// [END chat_create_message_app_cred]
107-
108-
// [START chat_create_message_app_cred_with_cards]
109-
/**
110-
* This sample shows how to create message with a card attached with app credential
111-
*
112-
* It relies on the OAuth2 scope 'https://www.googleapis.com/auth/chat.bot'
113-
* used by service accounts.
114-
*/
115-
function createMessageAppCredWithCards() {
116-
// Initialize request argument(s)
117-
// TODO(developer): Replace SPACE_NAME here.
118-
const parent = 'spaces/SPACE_NAME';
119-
const message = {
120-
text: 'Hello with app credential!',
121-
cardsV2: [{
122-
cardId: 'card-id',
123-
card: {
124-
header: {
125-
title: 'And with a card!',
94+
text: '👋🌎 Hello world! I created this message by calling ' +
95+
'the Chat API\'s `messages.create()` method.',
96+
cardsV2 : [{ card: {
97+
header: {
98+
title: 'About this message',
99+
imageUrl: 'https://fonts.gstatic.com/s/i/short-term/release/googlesymbols/info/default/24px.svg'
100+
},
101+
sections: [{
102+
header: 'Contents',
103+
widgets: [{ textParagraph: {
104+
text: '🔡 <b>Text</b> which can include ' +
105+
'hyperlinks 🔗, emojis 😄🎉, and @mentions 🗣️.'
106+
}}, { textParagraph: {
107+
text: '🖼️ A <b>card</b> to display visual elements' +
108+
'and request information such as text 🔤, ' +
109+
'dates and times 📅, and selections ☑️.'
110+
}}, { textParagraph: {
111+
text: '👉🔘 An <b>accessory widget</b> which adds ' +
112+
'a button to the bottom of a message.'
113+
}}
114+
]}, {
115+
header: "What's next",
116+
collapsible: true,
117+
widgets: [{ textParagraph: {
118+
text: "❤️ <a href='https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages.reactions/create'>Add a reaction</a>."
119+
}}, { textParagraph: {
120+
text: "🔄 <a href='https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/patch'>Update</a> " +
121+
"or ❌ <a href='https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages/delete'>delete</a> " +
122+
"the message."
123+
}
124+
}]
126125
}
127-
}
128-
}]
126+
]
127+
}}],
128+
accessoryWidgets: [{ buttonList: { buttons: [{
129+
text: 'View documentation',
130+
icon: { materialIcon: { name: 'link' }},
131+
onClick: { openLink: {
132+
url: 'https://developers.google.com/workspace/chat/create-messages'
133+
}}
134+
}]}}]
129135
};
130136
const parameters = {};
131137

@@ -137,7 +143,7 @@ function createMessageAppCredWithCards() {
137143
// Handle the response
138144
console.log(response);
139145
}
140-
// [END chat_create_message_app_cred_with_cards]
146+
// [END chat_create_message_app_cred]
141147

142148
// [START chat_create_message_user_cred]
143149
/**
@@ -151,7 +157,14 @@ function createMessageUserCred() {
151157
// TODO(developer): Replace SPACE_NAME here.
152158
const parent = 'spaces/SPACE_NAME';
153159
const message = {
154-
text: 'Hello with user credential!'
160+
text: '👋🌎 Hello world!' +
161+
'Text messages can contain things like:\n\n' +
162+
'* Hyperlinks 🔗\n' +
163+
'* Emojis 😄🎉\n' +
164+
'* Mentions of other Chat users `@` \n\n' +
165+
'For details, see the ' +
166+
'<https://developers.google.com/workspace/chat/format-messages' +
167+
'|Chat API developer documentation>.'
155168
};
156169

157170
// Make the request

0 commit comments

Comments
 (0)