This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
796c134
commit 5940f92
Showing
6 changed files
with
152 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,35 @@ | ||
const imageUrl = | ||
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1NiIgaGVpZ2h0PSI1NiIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiNmZmZmZmYiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBjbGFzcz0iZmVhdGhlciBmZWF0aGVyLW1lc3NhZ2UtY2lyY2xlIj48cGF0aCBkPSJNMjEgMTEuNWE4LjM4IDguMzggMCAwIDEtLjkgMy44IDguNSA4LjUgMCAwIDEtNy42IDQuNyA4LjM4IDguMzggMCAwIDEtMy44LS45TDMgMjFsMS45LTUuN2E4LjM4IDguMzggMCAwIDEtLjktMy44IDguNSA4LjUgMCAwIDEgNC43LTcuNiA4LjM4IDguMzggMCAwIDEgMy44LS45aC41YTguNDggOC40OCAwIDAgMSA4IDh2LjV6Ij48L3BhdGg+PC9zdmc+' // base64 -w0 <feather icon chat bubble white> | ||
|
||
;(window as any).DAChatButton = (onClick: (remove: () => void) => void) => { | ||
const button = document.createElement('button') | ||
button.id = 'distribute-aid-chat-button' | ||
const img = document.createElement('img') | ||
img.src = imageUrl | ||
button.appendChild(img) | ||
button.title = 'Launch chat!' | ||
button.onclick = () => { | ||
button.disabled = true | ||
onClick(() => { | ||
button.remove() | ||
}) | ||
} | ||
document.documentElement.appendChild(button) | ||
const style = document.createElement('style') | ||
style.type = 'text/css' | ||
style.textContent = `#distribute-aid-chat-button { | ||
background-color: #3777ec; | ||
position: absolute; | ||
bottom: 1rem; | ||
right: 1rem; | ||
border-radius: 100%; | ||
padding: 1rem 1rem 0.7rem 1rem; | ||
box-shadow: 0px 0px 10px 0px #0000008f; | ||
cursor: pointer; | ||
} | ||
#distribute-aid-chat-button:disabled { | ||
background-color: #b7b7b7; | ||
} | ||
` | ||
document.head.appendChild(style) | ||
} |
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,4 @@ | ||
declare module '*.svg' { | ||
const content: string | ||
export default content | ||
} |
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 |
---|---|---|
@@ -1,84 +1,108 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Distribute Aid: Chat</title> | ||
<meta name="chat:context" content="general" /> | ||
<meta name="chat:endpoint" content="{{GRAPHQL_API_ENDPOINT}}" /> | ||
<meta name="chat:apiKey" content="{{GRAPHQL_API_KEY}}" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://rsms.me/inter/inter-ui.css" | ||
integrity="sha256-cdb8LF5k6q+Mbl8Od9ARdnDUCjihJZocnLNXYUFtMmg=" | ||
crossorigin="" | ||
/> | ||
</head> | ||
|
||
<body> | ||
<h1>Distribute Aid: Chat</h1> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Distribute Aid: Chat</title> | ||
<meta name="chat:context" content="general" /> | ||
<meta name="chat:endpoint" content="{{GRAPHQL_API_ENDPOINT}}" /> | ||
<meta name="chat:apiKey" content="{{GRAPHQL_API_KEY}}" /> | ||
<link rel="stylesheet" href="https://rsms.me/inter/inter-ui.css" | ||
integrity="sha256-cdb8LF5k6q+Mbl8Od9ARdnDUCjihJZocnLNXYUFtMmg=" crossorigin="" /> | ||
</head> | ||
|
||
<p>This is the demo page for the <em>Distribute Aid</em> in-app-chat.</p> | ||
<body> | ||
<h1>Distribute Aid: Chat</h1> | ||
|
||
<p> | ||
It will be loaded from an external source, and will create it's DOM | ||
element with an overlaying chat window. | ||
</p> | ||
<p>This is the demo page for the <em>Distribute Aid</em> in-app-chat.</p> | ||
|
||
<p> | ||
Every chat has a <em>context</em>, which needs to be provided. In this | ||
example we use the <code>general</code> context, which is a public chat | ||
room that is available for all authenticated users. | ||
</p> | ||
<p> | ||
It will be loaded from an external source, and will create it's DOM | ||
element with an overlaying chat window. | ||
</p> | ||
|
||
<p> | ||
The API endpoint of the integration for this instance is | ||
<code>{{GRAPHQL_API_ENDPOINT}}</code>. | ||
</p> | ||
<p> | ||
Every chat has a <em>context</em>, which needs to be provided. In this | ||
example we use the <code>general</code> context, which is a public chat | ||
room that is available for all authenticated users. | ||
</p> | ||
|
||
<div id="tokenform"></div> | ||
<p> | ||
The API endpoint of the integration for this instance is | ||
<code>{{GRAPHQL_API_ENDPOINT}}</code>. | ||
</p> | ||
|
||
<script | ||
src="https://unpkg.com/react@16/umd/react.development.js" | ||
defer | ||
></script> | ||
<script | ||
src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" | ||
defer | ||
></script> | ||
<script | ||
src="https://media.twiliocdn.com/sdk/js/chat/v3.3/twilio-chat.min.js" | ||
defer | ||
></script> | ||
<script | ||
src="https://twemoji.maxcdn.com/v/latest/twemoji.min.js" | ||
crossorigin="anonymous" | ||
defer | ||
></script> | ||
<script src="./main.js" defer></script> | ||
<script src="./demo.js" defer></script> | ||
<script type="text/javascript"> | ||
const launchChat = token => | ||
DAChat({ | ||
context: document | ||
.querySelector("meta[name='chat:context']") | ||
.getAttribute("content"), | ||
apiKey: document | ||
.querySelector("meta[name='chat:apiKey']") | ||
.getAttribute("content"), | ||
apiEndpoint: document | ||
.querySelector("meta[name='chat:endpoint']") | ||
.getAttribute("content"), | ||
token | ||
}); | ||
<p><strong>Preview mode:</strong> Note that the chat will only load if the <code>DAChat:enabled</code> is set in | ||
localStorage. Run this command in the console to enable it: | ||
<code>window.localStorage.setItem('DAChat:enabled', '1')</code></p> | ||
|
||
window.onload = () => { | ||
ReactDOM.render( | ||
React.createElement(TokenForm, { | ||
onToken: token => launchChat(token) | ||
}), | ||
document.querySelector("#tokenform") | ||
); | ||
}; | ||
</script> | ||
</body> | ||
</html> | ||
<div id="tokenform"></div> | ||
|
||
<script src="https://cdn.rawgit.com/muicss/loadjs/4.2.0/dist/loadjs.min.js" defer></script> | ||
<script type="text/javascript"> | ||
const launchChat = token => | ||
DAChat({ | ||
context: document | ||
.querySelector("meta[name='chat:context']") | ||
.getAttribute("content"), | ||
apiKey: document | ||
.querySelector("meta[name='chat:apiKey']") | ||
.getAttribute("content"), | ||
apiEndpoint: document | ||
.querySelector("meta[name='chat:endpoint']") | ||
.getAttribute("content"), | ||
token | ||
}); | ||
|
||
const loadJsAsync = deps => loadjs(deps, { | ||
async: true, | ||
returnPromise: true | ||
}) | ||
|
||
const loadChat = () => { | ||
loadJsAsync([ | ||
'https://unpkg.com/react@16/umd/react.development.js', | ||
'https://unpkg.com/react-dom@16/umd/react-dom.development.js', | ||
'https://media.twiliocdn.com/sdk/js/chat/v3.3/twilio-chat.min.js', | ||
'https://twemoji.maxcdn.com/v/latest/twemoji.min.js', | ||
|
||
]) | ||
.then(() => loadJsAsync([ | ||
'./main.js', | ||
'./demo.js', | ||
])) | ||
.then(() => { | ||
ReactDOM.render( | ||
React.createElement(TokenForm, { | ||
onToken: token => launchChat(token) | ||
}), | ||
document.querySelector("#tokenform") | ||
); | ||
}) | ||
}; | ||
|
||
window.onload = () => { | ||
if (window.localStorage.getItem('DAChat:enabled') === '1') { | ||
if (document.cookie.split(';').filter((item) => item.trim().startsWith('DAChatopen=')).length) { | ||
loadChat() | ||
} else { | ||
console.log('not open') | ||
loadJsAsync([ | ||
'./chatbutton.js' | ||
]) | ||
.then(() => { | ||
DAChatButton((removeButton) => { | ||
document.cookie = 'DAChatopen=1' | ||
loadChat() | ||
.then(() => { | ||
removeButton() | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
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