update column to record if an app script is run for that row or not in google sheets
I am trying to run a google app script with Whatsapp business API to send messages to my customers directly from google sheets. The below app runs fine but every time I run it, it sends the message again and again to all customers irrespective of the same msg being sent to the same customer earlier.
Is there a way, I can add a column and update it automatically to record if the message has been sent to this customer in which case skip to the next (just like in mail merge scripts).
I have the below code and a screenshot of the image here
const WHATSAPP_ACCESS_TOKEN = "**My whatsapp token**"; const WHATSAPP_TEMPLATE_NAME = "**My template name**"; const LANGUAGE_CODE = "en"; const sendMessage_ = ({ recipient_number, customer_name, item_name, delivery_date, }) => { const apiUrl = "**My api url**"; const request = UrlFetchApp.fetch(apiUrl, { muteHttpExceptions: true, method: "POST", headers: { Authorization: `Bearer ${WHATSAPP_ACCESS_TOKEN}`, "Content-Type": "application/json", }, payload: JSON.stringify({ messaging_product: "whatsapp", type: "template", to: recipient_number, template: { name: WHATSAPP_TEMPLATE_NAME, language: { code: LANGUAGE_CODE }, components: [ { type: "body", parameters: [ { type: "text", text: customer_name, }, { type: "text", text: item_name, }, { type: "text", text: delivery_date, }, ], }, ], }, }), }); const { error } = JSON.parse(request); const status = error ? `Error: ${JSON.stringify(error)}` : `Message sent to ${recipient_number}`; Logger.log(status); }; const getSheetData_ = () => { const [header, ...rows] = SpreadsheetApp.getActiveSheet().getDataRange().getDisplayValues(); const data = []; rows.forEach((row) => { const recipient = { }; header.forEach((title, column) => { recipient[title] = row[column]; }); data.push(recipient); }); return data; }; const main = () => { const data = getSheetData_(); data.forEach((recipient) => { const status = sendMessage_({ recipient_number: recipient["Phone Number"].replace(/[^\d]/g, ""), customer_name: recipient["Customer Name"], item_name: recipient["Item Name"], delivery_date: recipient["Delivery Date"], }); }); };
Google oAuth2 - How to get user email address
Using bellow code I can get the access and refresh token:
private const SCOPE = 'https://www.googleapis.com/auth/adwords'; private const AUTHORIZATION_URI = 'https://accounts.google.com/o/oauth2/v2/auth'; private const OAUTH2_CALLBACK_PATH = ''; private const REDIRECT_URL = 'http://localhost:3000/google/google-ads/confirmed'; $code = $request->input('code'); $scope = $request->input('scope'); $state = $request->input('state'); $project_token = $request->input('project_token'); $project_name = $request->input('project_name'); $account_name = $request->input('account_name'); $account_id = $request->input('account_id'); $clientId = 'my-client-id--kh3el.apps.googleusercontent.com'; $clientSecret = 'my-clicent-secret4cCm'; $redirectUrl = self::REDIRECT_URL; $oauth2 = new OAuth2( [ 'clientId' => $clientId, 'clientSecret' => $clientSecret, 'authorizationUri' => self::AUTHORIZATION_URI, 'redirectUri' => $redirectUrl . self::OAUTH2_CALLBACK_PATH, 'tokenCredentialUri' => CredentialsLoader::TOKEN_CREDENTIAL_URI, 'scope' => self::SCOPE, // Create a 'state' token to prevent request forgery. See // https://developers.google.com/identity/protocols/OpenIDConnect#createxsrftoken // for details. 'state' => sha1(openssl_random_pseudo_bytes(1024)) ] ); // Set the authorization code and fetch refresh and access tokens. $oauth2->setCode($code); $authToken = $oauth2->fetchAuthToken(); $refreshToken = isset( $authToken['refresh_token'] ) ? $authToken['refresh_token'] : ''; $accessToken = $oauth2->getAccessToken();
now how can I get the emaill address? Is there any way?
setMediaAspectRatio(MediaAspectRatio.PORTRAIT) is not working Google ad manager
I need to load a Portrait Full-screen native ad.
I have set the nativeAdOptions like theseval nativeAdOptions = NativeAdOptions.Builder().setMediaAspectRatio(MediaAspectRatio.PORTRAIT).build()
and load the ad like this
AdLoader.Builder(context, adUnitId).withNativeAdOptions(nativeAdOptions)
Even I set the MediaAspectRatio
to MediaAspectRatio.PORTRAIT
. I am getting landscape ads.
Is there any issue with Google Ad Manager SDK or Do I need to specify any extra AdOptions?
This App is blocked error while extracting lifetime refresh token using OAuth Playground to supply to Azure Google Adwords linked service connector
While authorizing my Google Ads Account using OAuth Playground to retrieve a lifetime refresh token which could used to further create access tokens, the authorization is throwing This app is blocked
security error. I think this is because the GCP OAuth consent screen is not verified. But how do I verify my OAuth consent screen when I don't have an App domain name, since I'm using this as a one time activity to retrieve my refresh token using OAuth Playground?
Access WhatsApp messages from the day using API
I am building an application using the WhatsApp Business Cloud API. Essentially I want to know if it's possible to build an application that collects all the messages from the day and downloads it. Specifically the media attached to it using the API. As far as I know you can use webhooks to get incoming messages. But in order to do this the application has to be run forever, and my cousin has a problem with this as it could cause problems to run an application forever vs just run it once a day. I'm able to send messages using the API and a python wrapper but that's much more simple than what I'm trying to do. Aditionally, there is an option of using selenium but that's not really an automated solution to what we're trying to do because everytime selenium executes the browser we'd need to log in using the QR code. If anyone has any idea if this is possible (or not possible) I'd be very appreciative!
from heyoo import WhatsApp import logging import requests from dotenv import load_dotenv from flask import Flask, request, make_response app = Flask(__name__) token = 'EAAVk5rqOCsABAAcPPrZC6GnlZAJuykdFIQd4DhkuRVNeGntfFOU5jaK4jG2yCZBS6i7kFQGk3kRvDP0fExBXRsFyqWUqfVVJsSxeQdcA9XHWpRuUsnnuwqLcZAQpwTiuoZCXv4ixCcHYlPEe6NGHupCalHvWw9NQRoZAVnegU5ZCBvX6eO9E8vyum1lQ2SSt7OuUpdpIkmkyBK8tiEL8rpGwM8RrqZA3A10ZD' messenger = WhatsApp(token, phone_number_id='100398242927044') messenger.send_message('Hey its JJ ', '1xxxxxxxx') logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) print("hello") @app.route("/", methods=["GET", "POST"]) def hook():
//some code that isn't working yet
I'm new to all of this stuff so I don't really know how to set up a webhook either but my cousin who's business I'm building this app for doesn't ideally want to use a webhook.