Skip to content

Commit

Permalink
Feat/convert to notification service (#1)
Browse files Browse the repository at this point in the history
* fix: added features to enable sending complex status messages

* 1.1.6

* fix:typings

* 1.1.7

* fix: whatsapp service

* 1.1.8

* fix: updated to whatsapp service

* 1.1.9

* fix: peer dependency

* 1.1.10

* 1.1.11

* fix: to handle content templates

* 1.1.12

* fix: middleware

* 1.1.13

* fix: middleware

* 1.1.14

* fix: session handling

* 1.1.15

* fix: session handling

* fix: typings

* fix: typings

* 1.1.17

* fix: added one flavour of incoming messages

* fix: update hooks

* feat:conversation support

* 1.2.0

* fix: cleanup users

* fix: cleanup users

* 1.2.1

* fix: cleanup users

* 1.2.2

* fix: service export

* 1.2.3

* fix: startagentconversation

* 1.2.4

* fix: agency

* 1.2.5

* fix: authorization

* 1.2.6

* fix: message handling

* 1.2.7

* fix: message handling

* 1.2.8

* fix: message handling

* 1.2.9

* 1.2.10

* Commiting whatsapp messages

* chore: add liniting

* 1.2.12

* fix name

* 1.2.13

* fix: responses

* 1.2.14

* fix: conversations

* 1.2.15

* fix: conversations

* 1.2.16

* fix: updates to auto-response

* 1.2.17

* fix: updates to auto-response

* 1.2.18

* fix: updates to auto-response

* 1.2.19

* fix: sendAgentConversation

* 1.2.20

* fix: search for user conversations

* fix: validation wiht ports

* 1.2.21

* fix: validation with ports

* 1.2.22

* fix: no-old-conversations

* fix: no-old-conversations

* 1.2.23

* fix: release from conversation

* 1.2.24

* fix: release from conversation

* fix: undefined

* 1.2.25

* fix: medusa-plugin-whatsapp readme

* fix: notifications and resolution issues during tests

---------

Co-authored-by: Govind Diwakar <sgf@sourcegoodfood.com>
  • Loading branch information
SGFGOV and Govind Diwakar authored May 31, 2024
1 parent 293dba9 commit 3519c61
Show file tree
Hide file tree
Showing 21 changed files with 5,296 additions and 11,034 deletions.
122 changes: 122 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
module.exports = {
// parser: `@babel/eslint-parser`,
parserOptions: {
requireConfigFile: false,
ecmaFeatures: {
experimentalDecorators: true,
},
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["file-progress", "prettier"],
extends: [
"eslint:recommended",
"eslint-config-prettier",
"google",
"plugin:prettier/recommended",
],
rules: {
"file-progress/activate": 1,
/* "prettier/prettier": [
"warn",
{
singleQuote: false,
semi: true,
quoteProps: "consistent",
objectCurlySpacing: "always",
trailingComma: "all",
},
],*/
"prettier/prettier": [
"error",
{
endOfLine: "auto",
},
{
usePrettierrc: true,
},
],
"object-curly-spacing": [2, "always"],
quotes: [2, "double", { avoidEscape: true }],
curly: [2, "all"],
"new-cap": "off",
"require-jsdoc": "off",
semi: "error",
"no-unused-expressions": "off",
camelcase: "off",
"no-invalid-this": "off",
},
env: {
es6: true,
node: true,
jest: true,
},
ignorePatterns: [
"**/models",
"**/repositories",
"**/reports",
"**/dist",
"**/coverage",
],
overrides: [
{
files: ["*.ts"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint/eslint-plugin"],
extends: ["plugin:@typescript-eslint/recommended"],
rules: {
"valid-jsdoc": [
"error",
{
requireParamType: false,
requireReturnType: false,
prefer: {
arg: "param",
argument: "param",
class: "constructor",
return: "return",
virtual: "abstract",
},
},
],
"@typescript-eslint/explicit-function-return-type": ["error"],
"@typescript-eslint/no-non-null-assertion": ["off"],
"prettier/prettier": [
"error",
{
endOfLine: "auto",
},
{
usePrettierrc: true,
},
],
},
},
{
files: [
"**/common/**/*.ts",
"**/bin/**/*.ts",
"**/api/**/*.ts",
"**/medusa-js/**/resources/**/*.ts",
],
rules: {
"valid-jsdoc": ["off"],
},
},
{
// Medusa JS client
files: ["**/medusa-js/**/resources/**/*.ts"],
rules: {
"valid-jsdoc": ["off"],
},
},
{
files: ["**/api/**/*.ts"],
rules: {
"valid-jsdoc": ["off"],
"@typescript-eslint/explicit-function-return-type": ["off"],
"@typescript-eslint/no-var-requires": ["off"],
},
},
],
};
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
**/.DS_Store
.env*
/*.js
!.eslintrc.js

dist
coverage
Expand All @@ -14,14 +15,20 @@ services/
models/
subscribers/
migrations/

jobs/
loaders/
index.*
!index.ts

utils/
types/
!src/*
src/coverage
*.log

!src/services

./tsconfig.tsbuildinfo
./package-lock.json
./yarn.json
*.tgz
*.tgz
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ coverage
*.tgz

tsconfig.tsbuildinfo
tsconfig.json
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest:medusa-plugin-whatsapp ",
//"env": { "NODE_ENV": "test" },
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--detect-open-handles",
"--setupFiles",
"dotenv/config"
],
"console": "integratedTerminal",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
},
]
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ add to your plugins list
}
```

the whatsapp handler service need to implement the interface
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "medusa-plugin-whatsapp",
"version": "1.1.5",
"version": "1.2.25",
"description": "A plugin to integrate with medusa with whatsapp",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -24,16 +24,16 @@
"author": "Govind Diwakar <govind.diwakar@gmail.com>",
"license": "MIT",
"scripts": {
"clean": "./node_modules/.bin/rimraf services/ models/ migrations/ api/ utils/ subscribers/ index.js index.map.js",
"clean": "./node_modules/.bin/rimraf services/ models/ migrations/ api/ utils/ subscribers/ types/ index.js index.map.js",
"build": "npm run clean && tsc -p tsconfig.json",
"watch": "tsc --watch",
"test": "jest --coverage"
},
"devDependencies": {
"@medusajs/medusa": "^1.7.2",
"@medusajs/medusa": "^1.20.2",
"@types/express": "^4.17.13",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.15",
"@types/node": "^20.11.25",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
Expand All @@ -46,6 +46,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-file-progress": "^1.3.0",
"eslint-plugin-prettier": "^4.2.1",
"ioredis": "^5.3.2",
"jest": "^27.5.0",
"medusa-interfaces": "1.x",
"mongoose": "^6.2.0",
Expand All @@ -54,20 +55,21 @@
"supertest": "^6.3.3",
"ts-jest": "^27.1.3",
"ts-loader": "^9.2.6",
"typeorm": "^0.3.16",
"typescript": "^4.5.5"
},
"peerDependencies": {
"@medusajs/medusa": "latest",
"medusa-interfaces": "latest"
"medusa-interfaces": "latest",
"typeorm": "^0.3.16"
},
"dependencies": {
"body-parser": "^1.19.1",
"cors": "^2.8.5",
"express": "^4.17.2",
"medusa-core-utils": "^1.1.31",
"medusa-test-utils": "^1.1.37",
"twilio": "^3.84.0",
"typeorm": "0.3.14"
"twilio": "^3.84.0"
},
"jest": {
"globals": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Router } from "express";
import whatsAppReceiverRoute from "./routes";
import { WhatsappInterfaceOptions } from "../services/whatsapp-interface";
import { WhatsappInterfaceOptions } from "../services/whatsapp";
import { ConfigModule } from "@medusajs/medusa/dist/types/global";
import { getConfigFile } from "medusa-core-utils";
/* TODO second argument pluginConfig: Record<string, unknown> part of PR https://github.com/medusajs/medusa/pull/959 not yet in master */
Expand Down
13 changes: 10 additions & 3 deletions src/api/middleware/verify-twilio.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { NextFunction, Request, Response } from "express";
import { WhatsappInterfaceOptions } from "services/whatsapp-interface";
import { WhatsappInterfaceOptions } from "services/whatsapp";
import twilio from "twilio";

export default (options: WhatsappInterfaceOptions) => {
export default (options: WhatsappInterfaceOptions, path: string) => {
return (req: Request, res: Response, next: NextFunction) => {
const twilioSignature = req.headers["x-twilio-signature"];
const params = req.body;
let requestIsValid = false;
if (!params || params?.length == 0) {
requestIsValid = false;
} else {
const url = `${options.medusaServerProtocol}://${options.medusaServerHost}:${options.medusaServerPort}/whatsapp/received`;
let url;
if (options.medusaServerProtocol.toLowerCase() == "https") {
url = `${options.medusaServerProtocol}://${options.medusaServerHost}${path}`;
} else if (options.medusaServerPort && options.medusaServerPort != "") {
url = `${options.medusaServerProtocol}://${options.medusaServerHost}:${options.medusaServerPort}${path}`;
} else if (!options.medusaServerPort || options.medusaServerPort == "") {
url = `${options.medusaServerProtocol}://${options.medusaServerHost}${path}`;
}

requestIsValid = twilio.validateRequest(
options.auth_token,
Expand Down
Loading

0 comments on commit 3519c61

Please sign in to comment.