-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add curl commands for all code snippets in the Business Messages DevSite
Change-Id: I38ae0388fc92df33f13f2851fb899d19ae81a5f1
- Loading branch information
Showing
15 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Business Messages: curl | ||
|
||
These code snippets demonstrate how to perform operations with the Business Messages API using curl commands. | ||
|
||
This project contains multiple examples. Each file contains a single operation with the Business Messages API. | ||
|
||
To run the curl commands you need to be signed up with [Business Messages](https://developers.google.com/business-communications/business-messages/guides/set-up/register). | ||
|
||
## Documentation | ||
|
||
The documentation for the Business Messages API can be found [here](https://developers.google.com/business-communications/business-messages/reference/rest). | ||
|
||
## Prerequisite | ||
|
||
You must have the following software installed on your machine: | ||
|
||
- [Google Cloud SDK](https://cloud.google.com/sdk/) (aka gcloud) | ||
- [curl](https://curl.se/download.html) | ||
|
||
## Before you begin | ||
|
||
1. [Register with Business Messages](https://developers.google.com/business-communications/business-messages/guides/set-up/register). | ||
1. Once registered, follow the instructions to [enable the APIs for your project](https://developers.google.com/business-communications/business-messages/guides/set-up/register#enable-api). | ||
|
||
## How to run the curl commands? | ||
|
||
1. Locate the file with the command you want to execute. | ||
1. Replace all the placeholder strings that start with `__`, for example: `__CONVERSATION_ID__`. | ||
1. Make sure the path to your [service account key](https://developers.google.com/business-communications/business-messages/guides/quickstarts/prerequisite-setup?hl=en#create_a_service_account) is correct. | ||
1. Copy the content of the file to your terminal and execute the command. | ||
|
||
## Learn more | ||
|
||
To learn more about setting up Business Messages and supporting | ||
chat from Search and Maps, see the [documentation](https://developers.google.com/business-communications/business-messages/guides). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'fallback': 'Hello, check out this link https://www.google.com.', | ||
'text': 'Hello, here is some **bold text**, *italicized text*, and a [link](https://www.google.com).', | ||
'containsRichText': 'true', | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
} | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'text': 'Hello world!', | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
} | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/events?eventId=6a0af2c6-787d-4097-870d-93fe20351747" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'eventType': 'REPRESENTATIVE_JOINED', | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'HUMAN' | ||
} | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/events?eventId=6a0af2c6-787d-4097-870d-93fe20351747" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'eventType': 'TYPING_STARTED', | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
}, | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
# Replace the __CLIENT_ID__ | ||
# Replace the __CODE_CHALLENGE__ | ||
# Replace the __SCOPE__ | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'text': 'Sign in to continue the conversation.', | ||
'fallback': 'Visit support.growingtreebank.com to continue.', | ||
'suggestions': [ | ||
{ | ||
'authenticationRequest': { | ||
'oauth': { | ||
'clientId': '__CLIENT_ID__', | ||
'codeChallenge': '__CODE_CHALLENGE__', | ||
'scopes': [ | ||
'__SCOPE__', | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
} | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST \ | ||
"https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages?forceFallback=true" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'text': 'Hello world!', | ||
'fallback': 'Hello, world!\n\nSay \"Hello\" at https://www.growingtreebank.com', | ||
'suggestions': [ | ||
{ | ||
'action': { | ||
'text': 'Hello', | ||
'postbackData': 'hello-formal', | ||
'openUrlAction': { | ||
'url': 'https://www.growingtreebank.com', | ||
} | ||
}, | ||
}, | ||
], | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
} | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
}, | ||
'fallback': 'Hello, world!\nAn image has been sent with Business Messages.', | ||
'image': { | ||
'contentInfo':{ | ||
'altText': 'Image alternative text', | ||
'fileUrl': 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg', | ||
'forceRefresh': 'false' | ||
} | ||
}, | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'text': 'Would you like to chat with a live agent?', | ||
'fallback': 'Would you like to chat with a live agent?', | ||
'suggestions': [ | ||
{ | ||
'liveAgentRequest': {}, | ||
}, | ||
], | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
}, | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
}, | ||
'fallback': 'Card #1\nThe description for card #1\n\nCard #2\nThe description for card #2\n\nReply with \"Card #1\" or \"Card #2\"', | ||
'richCard': { | ||
'carouselCard': { | ||
'cardWidth': 'MEDIUM', | ||
'cardContents': [ | ||
{ | ||
'title': 'Card #1', | ||
'description': 'The description for card #1', | ||
'suggestions': [ | ||
{ | ||
'reply': { | ||
'text': 'Card #1', | ||
'postbackData': 'card_1' | ||
} | ||
} | ||
], | ||
'media': { | ||
'height': 'MEDIUM', | ||
'contentInfo': { | ||
'fileUrl': 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg', | ||
'forceRefresh': 'false', | ||
} | ||
} | ||
}, | ||
{ | ||
'title': 'Card #2', | ||
'description': 'The description for card #2', | ||
'suggestions': [ | ||
{ | ||
'reply': { | ||
'text': 'Card #2', | ||
'postbackData': 'card_2' | ||
} | ||
} | ||
], | ||
'media': { | ||
'height': 'MEDIUM', | ||
'contentInfo': { | ||
'fileUrl': 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg', | ||
'forceRefresh': 'false', | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
}, | ||
'fallback': 'Hello, world!\nSent with Business Messages\n\nReply with \"Suggestion #1\" or \"Suggestion #2\"', | ||
'richCard': { | ||
'standaloneCard': { | ||
'cardContent': { | ||
'title': 'Hello, world!', | ||
'description': 'Sent with Business Messages.', | ||
'media': { | ||
'height': 'TALL', | ||
'contentInfo':{ | ||
'altText': 'Google logo', | ||
'fileUrl': 'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', | ||
'forceRefresh': 'false' | ||
} | ||
}, | ||
'suggestions': [ | ||
{ | ||
'reply': { | ||
'text': 'Suggestion #1', | ||
'postbackData': 'suggestion_1' | ||
} | ||
}, | ||
{ | ||
'reply': { | ||
'text': 'Suggestion #2', | ||
'postbackData': 'suggestion_2' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'text': 'Contact support for help with this issue.', | ||
'fallback': 'Give us a call at +12223334444.', | ||
'suggestions': [ | ||
{ | ||
'action': { | ||
'text': 'Call support', | ||
'postbackData': 'call-support', | ||
'dialAction': { | ||
'phoneNumber': '+12223334444', | ||
} | ||
}, | ||
}, | ||
], | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
}, | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Replace the __CONVERSATION_ID__ | ||
# Make sure a service account key file exists at ./service_account_key.json | ||
|
||
curl -X POST "https://businessmessages.googleapis.com/v1/conversations/__CONVERSATION_ID__/messages" \ | ||
-H "Content-Type: application/json" \ | ||
-H "User-Agent: curl/business-messages" \ | ||
-H "`oauth2l header --json ./service_account_key.json businessmessages`" \ | ||
-d "{ | ||
'messageId': '86b11a9c-6d29-499a-b516-444e9d2a5543', | ||
'text': 'Hello world!', | ||
'fallback': 'Hello, world!\n\nSay \"Hello\" at https://www.growingtreebank.com', | ||
'suggestions': [ | ||
{ | ||
'action': { | ||
'text': 'Hello', | ||
'postbackData': 'hello-formal', | ||
'openUrlAction': { | ||
'url': 'https://www.growingtreebank.com', | ||
} | ||
}, | ||
}, | ||
], | ||
'representative': { | ||
'avatarImage': 'https://lh3.googleusercontent.com/LjlQXZGF-3C0yv99xAKpv942l62ZV8nhG59rR8PXbqR_ue2_AJY67X7dlEKi_a21vgswYqVD0E7fdFYcku4uQjDncYVSVA65IUBVRm4=w153', | ||
'displayName': 'Chatbot', | ||
'representativeType': 'BOT' | ||
}, | ||
}" |
Oops, something went wrong.