如何使用 Google App 脚本将消息从 google 表格发送到 WhatsApp?

发布于 2025-01-12 02:53:42 字数 131 浏览 0 评论 0原文

我似乎没有找到任何教程或可靠的免费资源来从 Google 应用程序脚本集成 WhatsApp 消息。我找到了附加组件,但它们是在发送一定数量的消息后付费的。我可以在应用程序脚本集成方面使用一些帮助。如果有人可以分享任何可以帮助我的资源,那就太好了。

I don't seem to find any tutorials or a reliable free resource to integrate WhatsApp messages from the Google App script. I've found add-ons but they are paid after a certain nu ber of messages sent. I could use some help with the App script Integration. If anyone can share any resources that can help me out with it would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书信已泛黄 2025-01-19 02:53:42

我想我能够找到有关使用 Sheets、App 脚本和 Whatsapp API 的特定参考,但它是西班牙语的。我能够翻译它,您也可以这样做,请随时查看它 这里

我编辑了代码并添加了翻译重要信息的注释

function addSheet() {

const spreadsheeturl = '##URL DE LA HOJA DE CALCULO##' //URL of the Sheet
const sheetname = '##NOMBRE DE LA HOJA DONDE TENEMOS ANOTADOS LOS TELÉFONOS Y LOS MENSAJES A ENVIAR##' //Name of the Sheet workbook that would be used with the phone numbers and where the messages would be sent
const columnatelefono = '##LETRA DE LA COLUMNA EN LA QUE VAS A ESCRIBIR EL TELÉFONO AL QUE ENVIAR EL MENSAJE POR WHATSAPP##' // Letter of the column where you would write the phone number
const columnamensaje = '##LETRA DE LA COLUMNA EN LA QUE VAS A ESCRIBIR EL MENSAJE A ENVIAR POR WHATSAPP##' // Letter of the column where you would write the message to be sent
const columnaenlace = '##LETRA DE LA COLUMNA EN LA QUE DESEAS QUE APAREZCA EL ENLACE DE WHATSAPP##' // Letter  of the column where you want to show the whatsapp link.

const columnas = {
    A: 0, B: 1, C: 2, D: 3,
    E: 4, F: 5, G: 6, H: 7,
    I: 8, J: 9, K: 10, L: 11,
    M: 12, N: 13, O: 14, P: 15,
    Q: 16, R: 17, S: 18, T: 19,
    U: 20, V: 21, W: 22, X: 23,
    Y: 24, Z: 25, a: 0, b: 1,
    c: 2, d: 3, e: 4, f: 5,
    g: 6, h: 7, i: 8, j: 9,
    k: 10, l: 11, m: 12, n: 13,
    o: 14, p: 15, q: 16, r: 17,
    s: 18, t: 19, u: 20, v: 21,
    w: 22, x: 23, y: 24, z: 25
}


const ss = SpreadsheetApp.openByUrl(spreadsheeturl)
const sh = ss.getSheetByName(sheetname)
const shlastrow = sh.getLastRow()
const shlastcolumn = sh.getLastColumn()
const shdatarange = sh.getRange(1, 1, shlastrow, shlastcolumn)
const shdata = shdatarange.getValues()
const columnatelefononumber = columnas[columnatelefono]
const columnamensajenumber = columnas[columnamensaje]
const columnaenlacenumber = columnas[columnaenlace]
function generaEnlacesWhatsapp() {
    for (var i in shdata) {
        shdata[i][columnaenlacenumber] = 'https://api.whatsapp.com/send?phone=' + shdata[i][columnatelefononumber] + '&text=' + encodeURI(shdata[i][columnamensajenumber])
    }
    sh.getRange(1, 1, shlastrow, shdata[i].length).setValues(shdata)
    SpreadsheetApp.flush()
    Utilities.sleep(4000)
    Logger.log('a otra cosa') //this means something else


    const newshlastrow = sh.getLastRow()
    const newshlastcolumn = sh.getLastColumn()
    const newshdatarange = sh.getRange(1, 1, newshlastrow, newshlastcolumn)

    const newshdata = newshdatarange.getValues()
    Logger.log(newshdata)
    for (const j in newshdata) {
        for (const k in newshdata[j]) {
            if (newshdata[j][k] == null || newshdata[j][k] == 'null' || newshdata[j][k] == 'NOT_FOUND') {
                newshdata[j][k] = ''
            }
        }
    }
    Logger.log(newshdata)
    sh.getRange(1, 1, shlastrow, newshdata[i].length).setValues(newshdata)
}

}

I think I was able to find the particular reference about using Sheets, App script and Whatsapp API, however it was in Spanish. I was able to translate it and you can do it too, feel free to review it here

I edited the code and added the comments translating the important information

function addSheet() {

const spreadsheeturl = '##URL DE LA HOJA DE CALCULO##' //URL of the Sheet
const sheetname = '##NOMBRE DE LA HOJA DONDE TENEMOS ANOTADOS LOS TELÉFONOS Y LOS MENSAJES A ENVIAR##' //Name of the Sheet workbook that would be used with the phone numbers and where the messages would be sent
const columnatelefono = '##LETRA DE LA COLUMNA EN LA QUE VAS A ESCRIBIR EL TELÉFONO AL QUE ENVIAR EL MENSAJE POR WHATSAPP##' // Letter of the column where you would write the phone number
const columnamensaje = '##LETRA DE LA COLUMNA EN LA QUE VAS A ESCRIBIR EL MENSAJE A ENVIAR POR WHATSAPP##' // Letter of the column where you would write the message to be sent
const columnaenlace = '##LETRA DE LA COLUMNA EN LA QUE DESEAS QUE APAREZCA EL ENLACE DE WHATSAPP##' // Letter  of the column where you want to show the whatsapp link.

const columnas = {
    A: 0, B: 1, C: 2, D: 3,
    E: 4, F: 5, G: 6, H: 7,
    I: 8, J: 9, K: 10, L: 11,
    M: 12, N: 13, O: 14, P: 15,
    Q: 16, R: 17, S: 18, T: 19,
    U: 20, V: 21, W: 22, X: 23,
    Y: 24, Z: 25, a: 0, b: 1,
    c: 2, d: 3, e: 4, f: 5,
    g: 6, h: 7, i: 8, j: 9,
    k: 10, l: 11, m: 12, n: 13,
    o: 14, p: 15, q: 16, r: 17,
    s: 18, t: 19, u: 20, v: 21,
    w: 22, x: 23, y: 24, z: 25
}


const ss = SpreadsheetApp.openByUrl(spreadsheeturl)
const sh = ss.getSheetByName(sheetname)
const shlastrow = sh.getLastRow()
const shlastcolumn = sh.getLastColumn()
const shdatarange = sh.getRange(1, 1, shlastrow, shlastcolumn)
const shdata = shdatarange.getValues()
const columnatelefononumber = columnas[columnatelefono]
const columnamensajenumber = columnas[columnamensaje]
const columnaenlacenumber = columnas[columnaenlace]
function generaEnlacesWhatsapp() {
    for (var i in shdata) {
        shdata[i][columnaenlacenumber] = 'https://api.whatsapp.com/send?phone=' + shdata[i][columnatelefononumber] + '&text=' + encodeURI(shdata[i][columnamensajenumber])
    }
    sh.getRange(1, 1, shlastrow, shdata[i].length).setValues(shdata)
    SpreadsheetApp.flush()
    Utilities.sleep(4000)
    Logger.log('a otra cosa') //this means something else


    const newshlastrow = sh.getLastRow()
    const newshlastcolumn = sh.getLastColumn()
    const newshdatarange = sh.getRange(1, 1, newshlastrow, newshlastcolumn)

    const newshdata = newshdatarange.getValues()
    Logger.log(newshdata)
    for (const j in newshdata) {
        for (const k in newshdata[j]) {
            if (newshdata[j][k] == null || newshdata[j][k] == 'null' || newshdata[j][k] == 'NOT_FOUND') {
                newshdata[j][k] = ''
            }
        }
    }
    Logger.log(newshdata)
    sh.getRange(1, 1, shlastrow, newshdata[i].length).setValues(newshdata)
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文