-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for submitting form to launch chat and passing input as C…
…onnect attributes
- Loading branch information
Showing
8 changed files
with
158 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
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,56 @@ | ||
# Submit form to launch a new chat | ||
|
||
Submit a form to launch a new chat and pass in values as contact attributes. | ||
|
||
This option allows you to launch a widget on form submission as well as pass values submitted to form as contact attributes. | ||
|
||
> Also refer to the Admin Guide documentation: https://docs.aws.amazon.com/connect/latest/adminguide/customize-widget-launch.html | ||
![](./formSubmitLaunchChat.gif) | ||
|
||
## Setup | ||
1. Create a form on your website: | ||
```html | ||
<form id="chatForm" onsubmit="return submitForm()"> | ||
<input type="text" id="firstName" placeholder="Enter your first name" required> | ||
<button id="launch-widget-btn" type="submit">Start Chat</button> | ||
</form> | ||
``` | ||
2. Host the snippet code on your website: | ||
```html | ||
<!-- EXAMPLE SNIPPET - Edit all '<REPLACE_ME>' values --> | ||
<script type="text/javascript"> | ||
function submitForm() { | ||
(function (w, d, x, id) { | ||
s = d.createElement('script'); | ||
s.src = 'https://<REPLACE_ME>.cloudfront.net/amazon-connect-chat-interface-client.js'; | ||
s.async = 1; | ||
s.id = id; | ||
d.getElementsByTagName('head')[0].appendChild(s); | ||
w[x] = w[x] || function () { (w[x].ac = w[x].ac || []).push(arguments) }; | ||
})(window, document, 'amazon_connect', '<REPLACE_ME>' /* Connect Widget ID */); | ||
amazon_connect('styles', { openChat: { color: '#ffffff', backgroundColor: '#123456' }, closeChat: { color: '#ffffff', backgroundColor: '#123456' } }); | ||
amazon_connect('snippetId', '<REPLACE_ME>' /* Connect Widget Snippet ID */); | ||
amazon_connect('supportedMessagingContentTypes', ['text/plain', 'text/markdown']); | ||
const customerName = document.getElementById('firstName').value; | ||
// Pass customer name as contact attribute | ||
amazon_connect('contactAttributes', { | ||
customer_name: customerName | ||
}); | ||
amazon_connect('customerDisplayName', function (callback) { | ||
callback(customerName); | ||
}); | ||
amazon_connect("customLaunchBehavior", { | ||
skipIconButtonAndAutoLaunch: true, | ||
}); | ||
//Make the page doesn't refresh on form submission | ||
return false; | ||
}; | ||
</script> | ||
``` |
Binary file added
BIN
+563 KB
hostedWidgetCustomization/formSubmitLaunchChat/formSubmitLaunchChat.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,92 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Start Amazon Connect Chat</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
form { | ||
background-color: white; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
input, | ||
button { | ||
display: block; | ||
width: 100%; | ||
margin-bottom: 10px; | ||
padding: 10px; | ||
box-sizing: border-box; | ||
} | ||
|
||
button { | ||
background-color: #123456; | ||
color: white; | ||
border: none; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #0e2a47; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<form id="chatForm" onsubmit="return submitForm()"> | ||
<input type="text" id="firstName" placeholder="Enter your first name" required> | ||
<button id="launch-widget-btn" type="submit">Start Chat</button> | ||
</form> | ||
|
||
<!-- EXAMPLE SNIPPET - Edit all '<REPLACE_ME>' values --> | ||
<script type="text/javascript"> | ||
function submitForm() { | ||
(function (w, d, x, id) { | ||
s = d.createElement('script'); | ||
s.src = 'https://<REPLACE_ME>.cloudfront.net/amazon-connect-chat-interface-client.js'; | ||
s.async = 1; | ||
s.id = id; | ||
d.getElementsByTagName('head')[0].appendChild(s); | ||
w[x] = w[x] || function () { (w[x].ac = w[x].ac || []).push(arguments) }; | ||
})(window, document, 'amazon_connect', '<REPLACE_ME>' /* Connect Widget ID */); | ||
|
||
amazon_connect('styles', { openChat: { color: '#ffffff', backgroundColor: '#123456' }, closeChat: { color: '#ffffff', backgroundColor: '#123456' } }); | ||
amazon_connect('snippetId', '<REPLACE_ME>' /* Connect Widget Snippet ID */); | ||
amazon_connect('supportedMessagingContentTypes', ['text/plain', 'text/markdown']); | ||
|
||
const customerName = document.getElementById('firstName').value; | ||
|
||
// Pass customer name as contact attribute | ||
amazon_connect('contactAttributes', { | ||
customer_name: customerName | ||
}); | ||
|
||
amazon_connect('customerDisplayName', function (callback) { | ||
callback(customerName); | ||
}); | ||
|
||
amazon_connect("customLaunchBehavior", { | ||
skipIconButtonAndAutoLaunch: true, | ||
}); | ||
|
||
//Make the page doesn't refresh on form submission | ||
return false; | ||
}; | ||
|
||
</script> | ||
</body> | ||
|
||
</html> |
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.