Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Reply added #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
*.log*
node_modules
node_modules
.idea/
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/gupshup-whatsapp-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions examples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,20 @@ client.optins.sendUserOptinRequest({
console.log("Optin request error: ", err)
})

// Send Quick-Reply Option Message
client.message.send({
channel : "whatsapp",
source : "917834811114",
destination : "919876543210",
'src.name': "GupshupAppTest",
message : {
type: "quick_reply",
msgid: "qr1",
content: {type:"text", header:"Hello", text:"Hello testing", caption:"Select one option"},
options: [{type:"text", title:"First"},{type:"text", title:"Second"}, {type:"text", title:"Third"}]
}
}).then((response) => {
console.log("Quick reply message sent", response)
}).catch(err => {
console.log("Quick reply message err:", err)
})
21 changes: 20 additions & 1 deletion lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,29 @@ interface ContactCard {
url: [ContactUrl]
}

interface QuickReplyContent {
type: string
header: string
text: string
caption: string
}

interface QuickReplyOptions {
type: string
title: string
}


export interface MessagePayload {
[key: string]: any; // For fixing Query String type error
isHSM?: string // true (for template message) || false (for session message)
type: 'text'| 'audio'| 'video'| 'file'| 'image' | 'location'| 'contact'| 'sticker'
type: 'text'| 'audio'| 'video'| 'file'| 'image' | 'location'| 'contact'| 'sticker' | 'quick_reply'
text?: string // The text message to be sent to the customer, in case of type=text, Eg: 'Hello, World!'
url?: string // The public URL where the file / audio / video attachment to be sent to the customer is hosted, Eg: https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3
originalUrl?: string // The public URL where the image to be sent to the customer is hosted. Only to be sent for type = image, Eg: https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg
previewUrl?: string // The public URL where a thumbnail of the image to be sent to the customer is hosted. Only to be sent for type = image, Eg: https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg
caption?: string // Add caption to media messages, applicable to media type = image|video|file, Eg: Media caption text,
msgid?: string // Add msgid to quick_reply messages

// For sending location
longitude?: number // Eg: 43.43
Expand All @@ -66,6 +80,11 @@ export interface MessagePayload {

// For Sending Contact Card
contact?: ContactCard

// For Sending quick_reply message
content?: QuickReplyContent
options?: [QuickReplyOptions]

}

export interface MessageBody {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "dist/gupshup",
"typings": "dist/gupshup",
"scripts": {
"clean": "rm -rf dist && mkdir dist",
"cp-ts": "cp lib/gupshup.d.ts dist/",
"clean": "rmdir /s dist && mkdir dist",
"cp-ts": "copy lib\\gupshup.d.ts dist\\",
"build:commonjs": "tsc",
"build": "npm run clean && npm run build:commonjs && npm run cp-ts",
"debug": "node examples/index.js",
Expand Down
15 changes: 15 additions & 0 deletions test/resources/message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,19 @@ describe('MESSAGES', () => {
done();
}).catch(err => done(new Error(JSON.stringify(err))))
}).timeout(5000)

it('Should be able to send message with quick reply options', (done) => {
gupshupInstance.message.send({
...messagePrefix,
message : {
type: "quick_reply",
msgid: "qr1",
content: {type:"text", header:"Hello", text:"Hello testing", caption:"Select one option"},
options: [{type:"text", title:"First"},{type:"text", title:"Second"}, {type:"text", title:"Third"}]
}
}).then((result) => {
assert.equal(result.status, 'submitted');
done();
}).catch(err => done(new Error(JSON.stringify(err))))
}).timeout(5000)
})