Skip to content

Instantly share code, notes, and snippets.

@rasolofonirina
Last active March 25, 2022 12:42
Show Gist options
  • Save rasolofonirina/3c78b958e5856c1c5d144eccef4a27b4 to your computer and use it in GitHub Desktop.
Save rasolofonirina/3c78b958e5856c1c5d144eccef4a27b4 to your computer and use it in GitHub Desktop.
First improvement
// Replace the line 252 to 316 by this
if (messageText) {
const greeting = new RegExp(/^(kaiz|kez|slt|salut|bjr|bonjour|hi|hello|hey|hola)/i)
if (messageText.match(greeting)) {
sayHello(senderID)
} else if (messageText.match('image')) {
sendImageMessage(senderID)
} else if (messageText.match('gif')) {
sendGifMessage(senderID)
} else if (messageText.match('audio')) {
sendAudioMessage(senderID)
} else if (messageText.match('video')) {
sendVideoMessage(senderID)
} else if (messageText.match('file')) {
sendFileMessage(senderID)
} else if (messageText.match('button')) {
sendButtonMessage(senderID)
} else if (messageText.match('generic')) {
sendGenericMessage(senderID)
} else if (messageText.match('receipt')) {
sendReceiptMessage(senderID)
} else if (messageText.match('quick reply')) {
sendQuickReply(senderID)
} else if (messageText.match('read receipt')) {
sendReadReceipt(senderID)
} else if (messageText.match('typing on')) {
sendTypingOn(senderID)
} else if (messageText.match('typing off')) {
sendTypingOff(senderID)
} else if (messageText.match('account linking')) {
sendAccountLinking(senderID)
} else {
sendTextMessage(senderID, messageText)
}
} else if (messageAttachments) {
sendTextMessage(senderID, "Message with attachment received")
}
}
// and add this function to say hello with the first name
function sayHello(senderID) {
request({
uri: `https://graph.facebook.com/v2.11/${senderID}`,
qs: { access_token: PAGE_ACCESS_TOKEN },
method: 'GET',
json: true
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
sendTextMessage(senderID, "Miarahaba an'i " + body.first_name)
} else {
console.log(error)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment