mcdev 6.0.1 → 6.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/.github/ISSUE_TEMPLATE/bug.yml +1 -0
  2. package/.github/PULL_REQUEST_TEMPLATE/pr_template_release.md +4 -3
  3. package/.vscode/settings.json +2 -2
  4. package/docs/dist/documentation.md +11 -23
  5. package/lib/Retriever.js +3 -2
  6. package/lib/metadataTypes/DataExtension.js +9 -18
  7. package/lib/metadataTypes/EmailSend.js +48 -28
  8. package/lib/metadataTypes/Journey.js +2 -2
  9. package/lib/metadataTypes/TransactionalSMS.js +18 -38
  10. package/lib/metadataTypes/definitions/MobileKeyword.definition.js +1 -1
  11. package/lib/util/file.js +9 -9
  12. package/package.json +7 -7
  13. package/test/mockRoot/.mcdevrc.json +1 -1
  14. package/test/resources/9999999/asset/block-1157-retrieve-expected.html +17 -8
  15. package/test/resources/9999999/automation/v1/scripts/get-response.json +32 -2
  16. package/test/resources/9999999/legacy/v1/beta/mobile/keyword/get-response.json +1 -1
  17. package/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json +1 -1
  18. package/test/resources/9999999/messaging/v1/sms/definitions/post-response.json +3 -1
  19. package/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/get-response.json +3 -1
  20. package/test/resources/9999999/messaging/v1/sms/definitions/testExisting_tsms/patch-response.json +3 -1
  21. package/test/resources/9999999/mobileKeyword/build-expected.amp +5 -1
  22. package/test/resources/9999999/mobileKeyword/get-expected.amp +5 -1
  23. package/test/resources/9999999/mobileKeyword/post-create-expected.amp +1 -1
  24. package/test/resources/9999999/mobileKeyword/template-expected.amp +5 -1
  25. package/test/resources/9999999/mobileMessage/build-expected.amp +6 -1
  26. package/test/resources/9999999/mobileMessage/get-expected.amp +6 -1
  27. package/test/resources/9999999/mobileMessage/post-create-expected.amp +1 -1
  28. package/test/resources/9999999/mobileMessage/post-update-expected.amp +1 -1
  29. package/test/resources/9999999/mobileMessage/template-expected.amp +6 -1
  30. package/test/resources/9999999/script/get_ampincluded-expected.json +8 -0
  31. package/test/resources/9999999/script/get_ampincluded-expected.ssjs +5 -0
  32. package/test/resources/9999999/script/get_ampscript-expected.html +5 -0
  33. package/test/resources/9999999/script/get_ampscript-expected.json +8 -0
  34. package/test/resources/9999999/script/get_mixed-expected.html +9 -0
  35. package/test/resources/9999999/script/get_mixed-expected.json +8 -0
  36. package/test/resources/9999999/transactionalSMS/build-expected.amp +105 -1
  37. package/test/resources/9999999/transactionalSMS/get-expected.amp +105 -1
  38. package/test/resources/9999999/transactionalSMS/patch-expected.amp +99 -1
  39. package/test/resources/9999999/transactionalSMS/post-expected.amp +99 -1
  40. package/test/resources/9999999/transactionalSMS/template-expected.amp +105 -1
  41. package/test/type.script.test.js +54 -14
  42. package/test/utils.js +3 -0
@@ -8,7 +8,7 @@
8
8
  "lastUpdated": "2023-03-08T16:30:00Z",
9
9
  "type": "ExactTarget.Mobile.Sms.Core.Entities.SmsMessageEntity",
10
10
  "name": "testExisting_mobileMessage",
11
- "text": "test message jb secret",
11
+ "text": "line1 %%[ SET @test='bla bla' ]%% line2 %%= v(@test) =%% still line2\nline3",
12
12
  "origin": "SMS Send",
13
13
  "code": {
14
14
  "id": "RXBwc0JoNk9jVTY0YWJNWFZDaGxvdzo4MTow",
@@ -6,7 +6,9 @@
6
6
  "status": "Active",
7
7
  "createdDate": "2022-11-07T02:24:00",
8
8
  "modifiedDate": "2022-11-07T02:25:00",
9
- "content": { "message": "\n%%[\n SET @key = 'new secret'\n]%%\n" },
9
+ "content": {
10
+ "message": "\n%%[\n SET @key = 'new secret'\n]%%\n%%[\n\nSET @unsubMessages = 'UnsubscribeSMSMessages_DEV'\nSET @unsubEvents = 'UnsubscribeSMS_DEV'\n\nSET @num = concat('+',[MOBILE_NUMBER])\nSET @rs= RetrieveSalesforceObjects('Contact','Id,et4ae5__HasOptedOutOfMobile__c', 'MobilePhone', '=',@num) \nSET @count = rowCount(@rs)\nVAR @response\nSET @rx = '^\\+((?:9[679]\\d8[035789]\\d|6[789]\\d|5[90]\\d|42\\d|3[578]\\d|2[1-689]\\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'\nSET @prefix = concat('+',RegExMatch(@num, @rx, 1))\nIF @count>0 THEN\n\tFOR @i = 1 TO @count DO\n\t\tSET @sk = Field(Row(@rs,@i),'Id')\n\t\tIF Field(Row(@rs,1),'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN\n\t\t\tSET @result = UpdateSingleSalesforceObject('Contact',@sk,'et4ae5__HasOptedOutOfMobile__c','true')\n\t\t\tIF @result == 0 THEN \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Error Updating')\n\t\t\tELSE \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Successfully Unsubscribed')\n\t\t\tENDIF\n\t\tELSE \n\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Already Unsubscribed')\n\t\tENDIF\n\n\tNEXT @i\n\n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'Found')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='You have unsubscribed and will no longer receive any messages.|'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nELSE \n\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'Status', 'Not Found') \n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'NotFound')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='Sorry, we could not find you'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nENDIF\n]%%\n%%=v(@response)=%%"
11
+ },
10
12
  "subscriptions": {
11
13
  "shortCode": "4912312345678",
12
14
  "countryCode": "",
@@ -7,7 +7,9 @@
7
7
  "status": "Active",
8
8
  "createdDate": "2022-11-07T02:24:00",
9
9
  "modifiedDate": "2022-11-07T02:25:00",
10
- "content": { "message": "%%[ SET @key = 'secret' ]%%" },
10
+ "content": {
11
+ "message": "line1 %%[ SET @test='bla bla' ]%% line2 %%= v(@test) =%% still line2\nline3 %%[ SET @key = 'secret' ]%%\n%%[\n\nSET @unsubMessages = 'UnsubscribeSMSMessages_DEV'\nSET @unsubEvents = 'UnsubscribeSMS_DEV'\n\nSET @num = concat('+',[MOBILE_NUMBER])\nSET @rs= RetrieveSalesforceObjects('Contact','Id,et4ae5__HasOptedOutOfMobile__c', 'MobilePhone', '=',@num) \nSET @count = rowCount(@rs)\nVAR @response\nSET @rx = '^\\+((?:9[679]\\d8[035789]\\d|6[789]\\d|5[90]\\d|42\\d|3[578]\\d|2[1-689]\\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'\nSET @prefix = concat('+',RegExMatch(@num, @rx, 1))\nIF @count>0 THEN\n\tFOR @i = 1 TO @count DO\n\t\tSET @sk = Field(Row(@rs,@i),'Id')\n\t\tIF Field(Row(@rs,1),'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN\n\t\t\tSET @result = UpdateSingleSalesforceObject('Contact',@sk,'et4ae5__HasOptedOutOfMobile__c','true')\n\t\t\tIF @result == 0 THEN \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Error Updating')\n\t\t\tELSE \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Successfully Unsubscribed')\n\t\t\tENDIF\n\t\tELSE \n\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Already Unsubscribed')\n\t\tENDIF\n\n\tNEXT @i\n\n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'Found')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='You have unsubscribed and will no longer receive any messages.|'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nELSE \n\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'Status', 'Not Found') \n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'NotFound')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='Sorry, we could not find you'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nENDIF\n]%%\n%%=v(@response)=%%"
12
+ },
11
13
  "subscriptions": {
12
14
  "shortCode": "4912312345678",
13
15
  "countryCode": "",
@@ -7,7 +7,9 @@
7
7
  "status": "Active",
8
8
  "createdDate": "2022-11-07T02:24:00",
9
9
  "modifiedDate": "2022-11-07T02:25:00",
10
- "content": { "message": "%%[ SET @key = 'secret' ]%%" },
10
+ "content": {
11
+ "message": "%%[ SET @key = 'secret' ]%%\n%%[\n\nSET @unsubMessages = 'UnsubscribeSMSMessages_DEV'\nSET @unsubEvents = 'UnsubscribeSMS_DEV'\n\nSET @num = concat('+',[MOBILE_NUMBER])\nSET @rs= RetrieveSalesforceObjects('Contact','Id,et4ae5__HasOptedOutOfMobile__c', 'MobilePhone', '=',@num) \nSET @count = rowCount(@rs)\nVAR @response\nSET @rx = '^\\+((?:9[679]\\d8[035789]\\d|6[789]\\d|5[90]\\d|42\\d|3[578]\\d|2[1-689]\\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'\nSET @prefix = concat('+',RegExMatch(@num, @rx, 1))\nIF @count>0 THEN\n\tFOR @i = 1 TO @count DO\n\t\tSET @sk = Field(Row(@rs,@i),'Id')\n\t\tIF Field(Row(@rs,1),'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN\n\t\t\tSET @result = UpdateSingleSalesforceObject('Contact',@sk,'et4ae5__HasOptedOutOfMobile__c','true')\n\t\t\tIF @result == 0 THEN \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Error Updating')\n\t\t\tELSE \n\t\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Successfully Unsubscribed')\n\t\t\tENDIF\n\t\tELSE \n\t\t\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'ContactId',@sk,'Status', 'Already Unsubscribed')\n\t\tENDIF\n\n\tNEXT @i\n\n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'Found')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='You have unsubscribed and will no longer receive any messages.|'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nELSE \n\tInsertData(@unsubEvents,'MobileNumber',@num,'Message',[MSG(0).NOUNS],'Status', 'Not Found') \n\tSET @msg = Lookup(@unsubMessages,'Message','Prefix',@prefix,'Type', 'NotFound')\n\tIF Length(@msg) == 0 THEN\n\t\tSET @response ='Sorry, we could not find you'\n\tELSE \n\t\tSET @response = @msg\n\tENDIF\nENDIF\n]%%\n%%=v(@response)=%%"
12
+ },
11
13
  "subscriptions": {
12
14
  "shortCode": "4912312345678",
13
15
  "countryCode": "",
@@ -1,2 +1,6 @@
1
1
  line1
2
- line2
2
+ %%[
3
+ SET @test = 'foobar'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
@@ -1,2 +1,6 @@
1
1
  line1
2
- line2
2
+ %%[
3
+ SET @test = 'bla bla'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
@@ -1,2 +1,2 @@
1
1
  line1
2
- line2
2
+ line2
@@ -1,2 +1,6 @@
1
1
  line1
2
- line2
2
+ %%[
3
+ SET @test = '{{{description}}}'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
@@ -1 +1,6 @@
1
- test message jb target secret
1
+ line1
2
+ %%[
3
+ SET @test = 'foobar'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
@@ -1 +1,6 @@
1
- test message jb secret
1
+ line1
2
+ %%[
3
+ SET @test = 'bla bla'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
@@ -1 +1 @@
1
- New Task Available
1
+ New Task Available
@@ -1 +1 @@
1
- test message jb new
1
+ test message jb new
@@ -1 +1,6 @@
1
- test message jb {{{secret}}}
1
+ line1
2
+ %%[
3
+ SET @test = '{{{description}}}'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
@@ -0,0 +1,8 @@
1
+ {
2
+ "createdDate": "2022-10-20T00:41:26.163",
3
+ "description": "",
4
+ "key": "testExisting_script_ampincluded",
5
+ "modifiedDate": "2022-10-20T00:41:26.163",
6
+ "name": "testExisting_script_ampincluded",
7
+ "r__folder_Path": "Scripts"
8
+ }
@@ -0,0 +1,5 @@
1
+ line1
2
+ %%[
3
+ SET @test = 'bla bla'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2 line3
@@ -0,0 +1,5 @@
1
+ line1
2
+ %%[
3
+ SET @test = 'bla bla'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2 line3
@@ -0,0 +1,8 @@
1
+ {
2
+ "createdDate": "2022-10-20T00:41:26.163",
3
+ "description": "",
4
+ "key": "testExisting_script_ampscript",
5
+ "modifiedDate": "2022-10-20T00:41:26.163",
6
+ "name": "testExisting_script_ampscript",
7
+ "r__folder_Path": "Scripts"
8
+ }
@@ -0,0 +1,9 @@
1
+ <script runat="server">
2
+ //dummy
3
+ </script>
4
+ line1
5
+ %%[
6
+ SET @test = 'bla bla'
7
+ ]%%
8
+ line2 %%= v(@test) =%% still line2; collapsed to line2 because
9
+ it's assumed HTML
@@ -0,0 +1,8 @@
1
+ {
2
+ "createdDate": "2022-10-20T00:41:26.163",
3
+ "description": "",
4
+ "key": "testExisting_script_mixed",
5
+ "modifiedDate": "2022-10-20T00:41:26.163",
6
+ "name": "testExisting_script_mixed",
7
+ "r__folder_Path": "Scripts"
8
+ }
@@ -1,4 +1,108 @@
1
-
1
+ line1
2
+ %%[
3
+ SET @test = 'foobar'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
2
7
  %%[
3
8
  SET @key = 'target secret'
4
9
  ]%%
10
+
11
+ %%[
12
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
13
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
14
+ SET @num = concat('+', [MOBILE_NUMBER])
15
+ SET @rs = RetrieveSalesforceObjects(
16
+ 'Contact',
17
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
18
+ 'MobilePhone',
19
+ '=',
20
+ @num
21
+ )
22
+ SET @count = rowCount(@rs)
23
+ VAR @response
24
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
25
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
26
+ IF @count>0 THEN
27
+ FOR @I = 1 TO @COUNT DO
28
+ SET @sk = Field(Row(@rs, @i), 'Id')
29
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
30
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
31
+ IF @result == 0 THEN
32
+ InsertData(
33
+ @unsubEvents,
34
+ 'MobileNumber',
35
+ @num,
36
+ 'Message',
37
+ [MSG(0).NOUNS],
38
+ 'ContactId',
39
+ @sk,
40
+ 'Status',
41
+ 'Error Updating'
42
+ )
43
+ ELSE
44
+ InsertData(
45
+ @unsubEvents,
46
+ 'MobileNumber',
47
+ @num,
48
+ 'Message',
49
+ [MSG(0).NOUNS],
50
+ 'ContactId',
51
+ @sk,
52
+ 'Status',
53
+ 'Successfully Unsubscribed'
54
+ )
55
+ ENDIF
56
+ ELSE
57
+ InsertData(
58
+ @unsubEvents,
59
+ 'MobileNumber',
60
+ @num,
61
+ 'Message',
62
+ [MSG(0).NOUNS],
63
+ 'ContactId',
64
+ @sk,
65
+ 'Status',
66
+ 'Already Unsubscribed'
67
+ )
68
+ ENDIF
69
+ NEXT @i
70
+ SET @msg = Lookup(
71
+ @unsubMessages,
72
+ 'Message',
73
+ 'Prefix',
74
+ @prefix,
75
+ 'Type',
76
+ 'Found'
77
+ )
78
+ IF Length(@msg) == 0 THEN
79
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
80
+ ELSE
81
+ SET @response = @msg
82
+ ENDIF
83
+ ELSE
84
+ InsertData(
85
+ @unsubEvents,
86
+ 'MobileNumber',
87
+ @num,
88
+ 'Message',
89
+ [MSG(0).NOUNS],
90
+ 'Status',
91
+ 'Not Found'
92
+ )
93
+ SET @msg = Lookup(
94
+ @unsubMessages,
95
+ 'Message',
96
+ 'Prefix',
97
+ @prefix,
98
+ 'Type',
99
+ 'NotFound'
100
+ )
101
+ IF Length(@msg) == 0 THEN
102
+ SET @response = 'Sorry, we could not find you'
103
+ ELSE
104
+ SET @response = @msg
105
+ ENDIF
106
+ ENDIF
107
+ ]%%
108
+ %%=v(@response)=%%
@@ -1,4 +1,108 @@
1
-
1
+ line1
2
+ %%[
3
+ SET @test = 'bla bla'
4
+ ]%%
5
+ line2 %%= v(@test) =%% still line2
6
+ line3
2
7
  %%[
3
8
  SET @key = 'secret'
4
9
  ]%%
10
+
11
+ %%[
12
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
13
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
14
+ SET @num = concat('+', [MOBILE_NUMBER])
15
+ SET @rs = RetrieveSalesforceObjects(
16
+ 'Contact',
17
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
18
+ 'MobilePhone',
19
+ '=',
20
+ @num
21
+ )
22
+ SET @count = rowCount(@rs)
23
+ VAR @response
24
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
25
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
26
+ IF @count>0 THEN
27
+ FOR @I = 1 TO @COUNT DO
28
+ SET @sk = Field(Row(@rs, @i), 'Id')
29
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
30
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
31
+ IF @result == 0 THEN
32
+ InsertData(
33
+ @unsubEvents,
34
+ 'MobileNumber',
35
+ @num,
36
+ 'Message',
37
+ [MSG(0).NOUNS],
38
+ 'ContactId',
39
+ @sk,
40
+ 'Status',
41
+ 'Error Updating'
42
+ )
43
+ ELSE
44
+ InsertData(
45
+ @unsubEvents,
46
+ 'MobileNumber',
47
+ @num,
48
+ 'Message',
49
+ [MSG(0).NOUNS],
50
+ 'ContactId',
51
+ @sk,
52
+ 'Status',
53
+ 'Successfully Unsubscribed'
54
+ )
55
+ ENDIF
56
+ ELSE
57
+ InsertData(
58
+ @unsubEvents,
59
+ 'MobileNumber',
60
+ @num,
61
+ 'Message',
62
+ [MSG(0).NOUNS],
63
+ 'ContactId',
64
+ @sk,
65
+ 'Status',
66
+ 'Already Unsubscribed'
67
+ )
68
+ ENDIF
69
+ NEXT @i
70
+ SET @msg = Lookup(
71
+ @unsubMessages,
72
+ 'Message',
73
+ 'Prefix',
74
+ @prefix,
75
+ 'Type',
76
+ 'Found'
77
+ )
78
+ IF Length(@msg) == 0 THEN
79
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
80
+ ELSE
81
+ SET @response = @msg
82
+ ENDIF
83
+ ELSE
84
+ InsertData(
85
+ @unsubEvents,
86
+ 'MobileNumber',
87
+ @num,
88
+ 'Message',
89
+ [MSG(0).NOUNS],
90
+ 'Status',
91
+ 'Not Found'
92
+ )
93
+ SET @msg = Lookup(
94
+ @unsubMessages,
95
+ 'Message',
96
+ 'Prefix',
97
+ @prefix,
98
+ 'Type',
99
+ 'NotFound'
100
+ )
101
+ IF Length(@msg) == 0 THEN
102
+ SET @response = 'Sorry, we could not find you'
103
+ ELSE
104
+ SET @response = @msg
105
+ ENDIF
106
+ ENDIF
107
+ ]%%
108
+ %%=v(@response)=%%
@@ -1,4 +1,102 @@
1
-
2
1
  %%[
3
2
  SET @key = 'secret'
4
3
  ]%%
4
+
5
+ %%[
6
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
7
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
8
+ SET @num = concat('+', [MOBILE_NUMBER])
9
+ SET @rs = RetrieveSalesforceObjects(
10
+ 'Contact',
11
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
12
+ 'MobilePhone',
13
+ '=',
14
+ @num
15
+ )
16
+ SET @count = rowCount(@rs)
17
+ VAR @response
18
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
19
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
20
+ IF @count>0 THEN
21
+ FOR @I = 1 TO @COUNT DO
22
+ SET @sk = Field(Row(@rs, @i), 'Id')
23
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
24
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
25
+ IF @result == 0 THEN
26
+ InsertData(
27
+ @unsubEvents,
28
+ 'MobileNumber',
29
+ @num,
30
+ 'Message',
31
+ [MSG(0).NOUNS],
32
+ 'ContactId',
33
+ @sk,
34
+ 'Status',
35
+ 'Error Updating'
36
+ )
37
+ ELSE
38
+ InsertData(
39
+ @unsubEvents,
40
+ 'MobileNumber',
41
+ @num,
42
+ 'Message',
43
+ [MSG(0).NOUNS],
44
+ 'ContactId',
45
+ @sk,
46
+ 'Status',
47
+ 'Successfully Unsubscribed'
48
+ )
49
+ ENDIF
50
+ ELSE
51
+ InsertData(
52
+ @unsubEvents,
53
+ 'MobileNumber',
54
+ @num,
55
+ 'Message',
56
+ [MSG(0).NOUNS],
57
+ 'ContactId',
58
+ @sk,
59
+ 'Status',
60
+ 'Already Unsubscribed'
61
+ )
62
+ ENDIF
63
+ NEXT @i
64
+ SET @msg = Lookup(
65
+ @unsubMessages,
66
+ 'Message',
67
+ 'Prefix',
68
+ @prefix,
69
+ 'Type',
70
+ 'Found'
71
+ )
72
+ IF Length(@msg) == 0 THEN
73
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
74
+ ELSE
75
+ SET @response = @msg
76
+ ENDIF
77
+ ELSE
78
+ InsertData(
79
+ @unsubEvents,
80
+ 'MobileNumber',
81
+ @num,
82
+ 'Message',
83
+ [MSG(0).NOUNS],
84
+ 'Status',
85
+ 'Not Found'
86
+ )
87
+ SET @msg = Lookup(
88
+ @unsubMessages,
89
+ 'Message',
90
+ 'Prefix',
91
+ @prefix,
92
+ 'Type',
93
+ 'NotFound'
94
+ )
95
+ IF Length(@msg) == 0 THEN
96
+ SET @response = 'Sorry, we could not find you'
97
+ ELSE
98
+ SET @response = @msg
99
+ ENDIF
100
+ ENDIF
101
+ ]%%
102
+ %%=v(@response)=%%
@@ -1,4 +1,102 @@
1
-
2
1
  %%[
3
2
  SET @key = 'new secret'
4
3
  ]%%
4
+
5
+ %%[
6
+ SET @unsubMessages = 'UnsubscribeSMSMessages_DEV'
7
+ SET @unsubEvents = 'UnsubscribeSMS_DEV'
8
+ SET @num = concat('+', [MOBILE_NUMBER])
9
+ SET @rs = RetrieveSalesforceObjects(
10
+ 'Contact',
11
+ 'Id,et4ae5__HasOptedOutOfMobile__c',
12
+ 'MobilePhone',
13
+ '=',
14
+ @num
15
+ )
16
+ SET @count = rowCount(@rs)
17
+ VAR @response
18
+ SET @rx = '^\+((?:9[679]\d8[035789]\d|6[789]\d|5[90]\d|42\d|3[578]\d|2[1-689]\d)|9[0-58]|8[1246]|6[0-6]|5[1-8]|4[013-9]|3[0-469]|2[70]|7|1)'
19
+ SET @prefix = concat('+', RegExMatch(@num, @rx, 1))
20
+ IF @count>0 THEN
21
+ FOR @I = 1 TO @COUNT DO
22
+ SET @sk = Field(Row(@rs, @i), 'Id')
23
+ IF Field(Row(@rs, 1), 'et4ae5__HasOptedOutOfMobile__c') == 'false' THEN
24
+ SET @result = UpdateSingleSalesforceObject('Contact', @sk, 'et4ae5__HasOptedOutOfMobile__c', 'true')
25
+ IF @result == 0 THEN
26
+ InsertData(
27
+ @unsubEvents,
28
+ 'MobileNumber',
29
+ @num,
30
+ 'Message',
31
+ [MSG(0).NOUNS],
32
+ 'ContactId',
33
+ @sk,
34
+ 'Status',
35
+ 'Error Updating'
36
+ )
37
+ ELSE
38
+ InsertData(
39
+ @unsubEvents,
40
+ 'MobileNumber',
41
+ @num,
42
+ 'Message',
43
+ [MSG(0).NOUNS],
44
+ 'ContactId',
45
+ @sk,
46
+ 'Status',
47
+ 'Successfully Unsubscribed'
48
+ )
49
+ ENDIF
50
+ ELSE
51
+ InsertData(
52
+ @unsubEvents,
53
+ 'MobileNumber',
54
+ @num,
55
+ 'Message',
56
+ [MSG(0).NOUNS],
57
+ 'ContactId',
58
+ @sk,
59
+ 'Status',
60
+ 'Already Unsubscribed'
61
+ )
62
+ ENDIF
63
+ NEXT @i
64
+ SET @msg = Lookup(
65
+ @unsubMessages,
66
+ 'Message',
67
+ 'Prefix',
68
+ @prefix,
69
+ 'Type',
70
+ 'Found'
71
+ )
72
+ IF Length(@msg) == 0 THEN
73
+ SET @response = 'You have unsubscribed and will no longer receive any messages.|'
74
+ ELSE
75
+ SET @response = @msg
76
+ ENDIF
77
+ ELSE
78
+ InsertData(
79
+ @unsubEvents,
80
+ 'MobileNumber',
81
+ @num,
82
+ 'Message',
83
+ [MSG(0).NOUNS],
84
+ 'Status',
85
+ 'Not Found'
86
+ )
87
+ SET @msg = Lookup(
88
+ @unsubMessages,
89
+ 'Message',
90
+ 'Prefix',
91
+ @prefix,
92
+ 'Type',
93
+ 'NotFound'
94
+ )
95
+ IF Length(@msg) == 0 THEN
96
+ SET @response = 'Sorry, we could not find you'
97
+ ELSE
98
+ SET @response = @msg
99
+ ENDIF
100
+ ENDIF
101
+ ]%%
102
+ %%=v(@response)=%%