Last active
February 17, 2022 14:12
-
-
Save haqiramadhani/effb21021bc68278b71a87c8b30d936f to your computer and use it in GitHub Desktop.
Membuat contact di google dengan google app script, sync ke android.
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
function test() { | |
createContact('Test Contact', '08273488734', ''); | |
} | |
function doGet( req ) { | |
const { action, ...data } = req.parameter; | |
switch(action) { | |
case "create": | |
const { name, phone, email } = data; | |
createContact( name, phone, email ); | |
return response().json({ | |
sucess: true, | |
message: 'Berhasil menyimpan kontak ke Google Contacts' | |
}); | |
break; | |
default: | |
break; | |
} | |
} | |
function createContact(name, phone, email) { | |
const contact = ContactsApp.createContact(name, '', ''); | |
contact.setMobilePhone(phone); | |
if (email) contact.setPrimaryEmail(email); | |
const group = ContactsApp.getContactGroup('System Group: My Contacts'); | |
group.addContact(contact); | |
return contact; | |
} | |
function response() { | |
return { | |
json: function(data) { | |
return ContentService | |
.createTextOutput(JSON.stringify(data)) | |
.setMimeType(ContentService.MimeType.JSON); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment