bep40 commited on
Commit
b44dcec
·
verified ·
1 Parent(s): f94335e

Fix Zalo: use conversation deep link instead of profile link, copy text first then open chat

Browse files
Files changed (1) hide show
  1. index.html +24 -10
index.html CHANGED
@@ -1541,7 +1541,7 @@ return div;
1541
  }
1542
 
1543
  function shareChatToZalo(msgEl){
1544
- // Lấy toàn bộ nội dung hội thoại (cả user + bot gần nhất)
1545
  let body=document.getElementById('chatBody');
1546
  let allMsgs=body.querySelectorAll('.chat-msg');
1547
  let lines=[];
@@ -1555,19 +1555,33 @@ lines.push(role+' '+txt);
1555
  });
1556
  let text=lines.join('\n\n').substring(0,3000);
1557
  text='[V.AI STUDIO - Tư vấn thiết bị nhà bếp]\n\n'+text+'\n\n---\nGửi từ: '+location.origin;
1558
- // Copy vào clipboard trước
 
1559
  if(navigator.clipboard){
1560
- navigator.clipboard.writeText(text).then(()=>{
1561
- showToast('✅ Đã sao chép nội dung! Dán vào Zalo để gửi.');
1562
- setTimeout(()=>{window.open('https://zalo.me/0981873395','_blank')},800);
1563
- }).catch(()=>{fallbackCopyAndOpenZalo(text)});
1564
- }else{fallbackCopyAndOpenZalo(text)}
1565
  }
1566
- function fallbackCopyAndOpenZalo(text){
1567
  let ta=document.createElement('textarea');ta.value=text;ta.style.cssText='position:fixed;top:-9999px';
1568
  document.body.appendChild(ta);ta.select();document.execCommand('copy');document.body.removeChild(ta);
1569
- showToast('✅ Đã sao chép nội dung! Dán vào Zalo để gửi.');
1570
- setTimeout(()=>{window.open('https://zalo.me/0981873395','_blank')},800);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1571
  }
1572
 
1573
  function showTyping(){
 
1541
  }
1542
 
1543
  function shareChatToZalo(msgEl){
1544
+ // Lấy toàn bộ nội dung hội thoại
1545
  let body=document.getElementById('chatBody');
1546
  let allMsgs=body.querySelectorAll('.chat-msg');
1547
  let lines=[];
 
1555
  });
1556
  let text=lines.join('\n\n').substring(0,3000);
1557
  text='[V.AI STUDIO - Tư vấn thiết bị nhà bếp]\n\n'+text+'\n\n---\nGửi từ: '+location.origin;
1558
+ // Copy vào clipboard
1559
+ var copied=false;
1560
  if(navigator.clipboard){
1561
+ try{navigator.clipboard.writeText(text);copied=true}catch(e){}
 
 
 
 
1562
  }
1563
+ if(!copied){
1564
  let ta=document.createElement('textarea');ta.value=text;ta.style.cssText='position:fixed;top:-9999px';
1565
  document.body.appendChild(ta);ta.select();document.execCommand('copy');document.body.removeChild(ta);
1566
+ }
1567
+ // Mở Zalo chat — thử deep link trước, fallback web
1568
+ showToast('✅ Đã sao chép! Zalo đang mở — hãy DÁN nội dung để gửi.');
1569
+ setTimeout(function(){
1570
+ // Thử mở app Zalo trực tiếp vào chat
1571
+ var phone='0981873395';
1572
+ var isMobile=/Android|iPhone|iPad/i.test(navigator.userAgent);
1573
+ if(isMobile){
1574
+ // Deep link mở thẳng chat trong app Zalo
1575
+ var appLink='https://zalo.me/conversation?phone='+phone;
1576
+ var w=window.open(appLink,'_blank');
1577
+ // Nếu app không mở (timeout), fallback sang OA chat
1578
+ setTimeout(function(){
1579
+ if(!w||w.closed){window.open('https://oa.zalo.me/home','_blank')}
1580
+ },2000);
1581
+ }else{
1582
+ window.open('https://chat.zalo.me/?phone='+phone,'_blank');
1583
+ }
1584
+ },600);
1585
  }
1586
 
1587
  function showTyping(){