-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
내정보 페이지 채널톡 연동 #417
Merged
Merged
내정보 페이지 채널톡 연동 #417
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,200 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
declare global { | ||
interface Window { | ||
ChannelIO?: IChannelIO; | ||
ChannelIOInitialized?: boolean; | ||
} | ||
} | ||
|
||
interface IChannelIO { | ||
c?: (...args: any) => void; | ||
q?: [methodName: string, ...args: any[]][]; | ||
(...args: any): void; | ||
} | ||
|
||
interface BootOption { | ||
appearance?: string; | ||
customLauncherSelector?: string; | ||
hideChannelButtonOnBoot?: boolean; | ||
hidePopup?: boolean; | ||
language?: string; | ||
memberHash?: string; | ||
memberId?: string; | ||
pluginKey: string; | ||
profile?: Profile; | ||
trackDefaultEvent?: boolean; | ||
trackUtmSource?: boolean; | ||
unsubscribe?: boolean; | ||
unsubscribeEmail?: boolean; | ||
unsubscribeTexting?: boolean; | ||
zIndex?: number; | ||
} | ||
|
||
interface Callback { | ||
(error: Error | null, user: CallbackUser | null): void; | ||
} | ||
|
||
interface CallbackUser { | ||
alert: number; | ||
avatarUrl: string; | ||
id: string; | ||
language: string; | ||
memberId: string; | ||
name?: string; | ||
profile?: Profile | null; | ||
tags?: string[] | null; | ||
unsubscribeEmail: boolean; | ||
unsubscribeTexting: boolean; | ||
} | ||
|
||
interface UpdateUserInfo { | ||
language?: string; | ||
profile?: Profile | null; | ||
profileOnce?: Profile; | ||
tags?: string[] | null; | ||
unsubscribeEmail?: boolean; | ||
unsubscribeTexting?: boolean; | ||
} | ||
|
||
interface Profile { | ||
[key: string]: string | number | boolean | null | undefined; | ||
} | ||
|
||
interface FollowUpProfile { | ||
name?: string | null; | ||
mobileNumber?: string | null; | ||
email?: string | null; | ||
} | ||
|
||
interface EventProperty { | ||
[key: string]: string | number | boolean | null | undefined; | ||
} | ||
|
||
type Appearance = "light" | "dark" | "system" | null; | ||
|
||
class ChannelService { | ||
loadScript() { | ||
(function () { | ||
const w = window; | ||
if (w.ChannelIO) { | ||
return w.console.error("ChannelIO script included twice."); | ||
} | ||
const ch: IChannelIO = function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
ch.c?.(arguments); | ||
}; | ||
ch.q = []; | ||
ch.c = function (args) { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
ch.q?.push(args); | ||
}; | ||
w.ChannelIO = ch; | ||
function l() { | ||
if (w.ChannelIOInitialized) { | ||
return; | ||
} | ||
w.ChannelIOInitialized = true; | ||
const s = document.createElement("script"); | ||
s.type = "text/javascript"; | ||
s.async = true; | ||
s.src = "https://cdn.channel.io/plugin/ch-plugin-web.js"; | ||
const x = document.getElementsByTagName("script")[0]; | ||
if (x.parentNode) { | ||
x.parentNode.insertBefore(s, x); | ||
} | ||
} | ||
if (document.readyState === "complete") { | ||
l(); | ||
} else { | ||
w.addEventListener("DOMContentLoaded", l); | ||
w.addEventListener("load", l); | ||
} | ||
})(); | ||
} | ||
|
||
boot(option: BootOption, callback?: Callback) { | ||
window.ChannelIO?.("boot", option, callback); | ||
} | ||
|
||
shutdown() { | ||
window.ChannelIO?.("shutdown"); | ||
} | ||
|
||
showMessenger() { | ||
window.ChannelIO?.("showMessenger"); | ||
} | ||
|
||
hideMessenger() { | ||
window.ChannelIO?.("hideMessenger"); | ||
} | ||
|
||
openChat(chatId?: string | number, message?: string) { | ||
window.ChannelIO?.("openChat", chatId, message); | ||
} | ||
|
||
track(eventName: string, eventProperty?: EventProperty) { | ||
window.ChannelIO?.("track", eventName, eventProperty); | ||
} | ||
|
||
onShowMessenger(callback: () => void) { | ||
window.ChannelIO?.("onShowMessenger", callback); | ||
} | ||
|
||
onHideMessenger(callback: () => void) { | ||
window.ChannelIO?.("onHideMessenger", callback); | ||
} | ||
|
||
onBadgeChanged(callback: (unread: number, alert: number) => void) { | ||
window.ChannelIO?.("onBadgeChanged", callback); | ||
} | ||
|
||
onChatCreated(callback: () => void) { | ||
window.ChannelIO?.("onChatCreated", callback); | ||
} | ||
|
||
onFollowUpChanged(callback: (profile: FollowUpProfile) => void) { | ||
window.ChannelIO?.("onFollowUpChanged", callback); | ||
} | ||
|
||
onUrlClicked(callback: (url: string) => void) { | ||
window.ChannelIO?.("onUrlClicked", callback); | ||
} | ||
|
||
clearCallbacks() { | ||
window.ChannelIO?.("clearCallbacks"); | ||
} | ||
|
||
updateUser(userInfo: UpdateUserInfo, callback?: Callback) { | ||
window.ChannelIO?.("updateUser", userInfo, callback); | ||
} | ||
|
||
addTags(tags: string[], callback?: Callback) { | ||
window.ChannelIO?.("addTags", tags, callback); | ||
} | ||
|
||
removeTags(tags: string[], callback?: Callback) { | ||
window.ChannelIO?.("removeTags", tags, callback); | ||
} | ||
|
||
setPage(page: string) { | ||
window.ChannelIO?.("setPage", page); | ||
} | ||
|
||
resetPage() { | ||
window.ChannelIO?.("resetPage"); | ||
} | ||
|
||
showChannelButton() { | ||
window.ChannelIO?.("showChannelButton"); | ||
} | ||
|
||
hideChannelButton() { | ||
window.ChannelIO?.("hideChannelButton"); | ||
} | ||
|
||
setAppearance(appearance: Appearance) { | ||
window.ChannelIO?.("setAppearance", appearance); | ||
} | ||
} | ||
|
||
export default new ChannelService(); |
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ import { SetNickNamePage } from "@/app/login/SetNicknamePage"; | |
import { RetrospectAnalysisPage } from "@/app/retrospect/analysis/RetrospectAnalysisPage"; | ||
import { TemplateListPage } from "@/app/retrospect/template/list/TemplateListPage"; | ||
import { RecommendDonePage } from "@/app/retrospect/template/recommend/RecommendDonePage"; | ||
import { RecommendSearch } from "@/app/retrospect/template/recommend/RecommendSearch"; | ||
import { RecommendTemplatePage } from "@/app/retrospect/template/recommend/RecommendTemplatePage"; | ||
import { RetrospectCreate } from "@/app/retrospectCreate/RetrospectCreate"; | ||
import { RetrospectCreateComplete } from "@/app/retrospectCreate/RetrospectCreateComplete"; | ||
|
@@ -40,7 +41,7 @@ import { RetrospectWritePage } from "@/app/write/RetrospectWritePage.tsx"; | |
import GlobalLayout from "@/layout/GlobalLayout.tsx"; | ||
import { HomeLayout } from "@/layout/HomeLayout"; | ||
import { RequireLoginLayout } from "@/layout/RequireLoginLayout"; | ||
import { RecommendSearch } from "@/app/retrospect/template/recommend/RecommendSearch"; | ||
import ChannelService from "@/lib/channel-talk/service"; | ||
|
||
type RouteChildren = { | ||
auth: boolean; | ||
|
@@ -256,5 +257,9 @@ const router = createBrowserRouter([ | |
]); | ||
|
||
export const Routers = () => { | ||
ChannelService.loadScript(); | ||
ChannelService.boot({ | ||
pluginKey: import.meta.env.VITE_CHANNELTALK_PLUGIN_KEY, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 환경 변수 공유해주시면, 플랫폼에도 잘 등록을 해놓겠습니다 :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! |
||
}); | ||
return <RouterProvider router={router} />; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
location 값에 따라 코드로 채널톡 버튼을 숨겨주는 것도 좋은 방법이지만,
혹시 채널톡에서 제공하는 화이트리스트 관리 기능을 사용해보면 어떨까요?!
혹여나 변동 사항이 생기게 된다면 다시 소스 코드를 고치고 배포하는 과정이 필요할 것 같은데 채널톡 백오피스에서 제공하는 화이트리스트를 사용하게 되면 조금 더 과정이 편해질 것 같다는 생각이 듭니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 요거 설정해봤는데, 채널톡이 SPA 환경에서 URL 변경되는 걸 인지하지 못해서 아래와 같이 제대로 작동하지 않더라구요!
그래서 사이트 최초 진입 시에 채널톡 부트시키고, 경로 이동 시 버튼만 hide/show로 설정해두었습니다.
혹시 제가 놓친게 있다면 알려주세요! 😸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 코드를 보니까 그러네요!
생각해보니 예전에 채널톡 화이트리스트를 적용했던 프로젝트는 Next로 구성된 프로젝트였던 기억이..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네네 일단 요렇게 머지하께요!