简体   繁体   English

使用 Whatsapp API 开发 Chrome 扩展程序

[英]Chrome Extension Development using the Whatsapp API

I am trying to make a chrome extension that uses the WhatsApp API to share the link of the page I am at with just a click on the extension.我正在尝试制作一个 chrome 扩展,它使用 WhatsApp API 来分享我所在页面的链接,只需点击扩展即可。 The API is - https://wa.me/?text=urlencodedtext , where I provide the urlencodedtext. API 是 - https://wa.me/?text=urlencodedtext ,我在其中提供 urlencodedtext。

the code I have written to perform this is - ( function(){ const YOUR_PHONE=''; window.open( https://api.whatsapp.com/send?phone=${YOUR_PHONE}&text=${encodeURIComponent(location.href)} ); } )();我编写的代码是 - ( function(){ const YOUR_PHONE=''; window.open( https://api.whatsapp.com/send?phone=${YOUR_PHONE}&text=${encodeURIComponent(location.href)} ); } )();

The above code redirects me to the Whatsapp page.上面的代码将我重定向到 Whatsapp 页面。 ScreenShot Being directed to the Whatsapp page make the process longer.屏幕截图被定向到 Whatsapp 页面会使过程更长。 Is there a way I can skip the Whatsapp page and go directly to the web whatsapp (or the desktop whatsapp).有没有办法可以跳过Whatsapp页面并直接转到网络whatsapp(或桌面whatsapp)。

I do not believe there is currently anyway to do this using that URL.我不相信目前无论如何都可以使用该 URL 来执行此操作。

On Web, when you visit : https://api.whatsapp.com/send?phone=xxxxx&text=yyyy It will show an intermediate page with a "Send" button which would send via WhatsApp Web if you already have it configured.在 Web 上,当您访问: https ://api.whatsapp.com/send?phone=xxxxx&text=yyyy 它将显示一个带有“发送”按钮的中间页面,如果您已经配置了它,它将通过 WhatsApp Web 发送。

However On Mobile, when you visit the same URL, it should load your WhatsApp App with the content , ready for you to press send.但是,在移动设备上,当您访问相同的 URL 时,它应该会加载您的 WhatsApp 应用程序和内容,准备好按发送键。

For the extension you are trying to write, you would have to do the following:对于您尝试编写的扩展,您必须执行以下操作:

  1. Receive the inputs from the Extension User.接收来自扩展用户的输入。
  2. Check if WhatsApp Web is opened on any tab (meaning you need to have permission to view all open browser tabs) or Open a New Tab with WhatApp Web.检查 WhatsApp Web 是否在任何选项卡上打开(意味着您需要有权查看所有打开的浏览器选项卡)或使用 WhatApp Web 打开新选项卡。
  3. Use Javascript to initiate a new message with the number you want (meaning you need permission to edit browser pages)使用 Javascript 以您想要的号码发起新消息(意味着您需要获得编辑浏览器页面的权限)

I don't believe you can use the WhatsApp URL (it is not the API) you mentioned to achieve your purpose.我不相信您可以使用您提到的 WhatsApp URL(它不是 API)来实现您的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM