Wednesday 19 July 2017

GroupMe Bot that Responds to a Specific User

I've been tweaking a copy of the GroupMe Node JS sample bot provided here, and I'm trying to create a simple bot that responds to one particular user in my group chat every time he says a certain word. I was able to tweak it to respond to the word, but I have not found a way to only have it respond to a certain user. The relevant code is located in the file "bot.js." The section "function respond()" contains the default trigger text for the reply (This is the original code, my only modification was replacing "/cool guy" with the new word)function respond() { var request = JSON.parse(this.req.chunks[0]), botRegex = /^\/cool guy$/; if(request.text && botRegex.test(request.text)) { this.res.writeHead(200); postMessage(); this.res.end(); } else { console.log("don't care"); this.res.writeHead(200); this.res.end(); } } Is there a line I can add to "function respond()" to check for the username as well as the text?

Submitted July 19, 2017 at 06:19PM by CCFM

No comments:

Post a Comment