Bot framework V4 how to add facebook receipt with discount - node.js

Is it possible to use the Discount option from Facebook Messenger's Receipt Template with Bot Framework V4?
Because I tried searching the samples, but they require string values, while the Facebook Template requires arrays.
Example:
"adjustments":[
{
"name":"New Customer Discount",
"amount":20
},
{
"name":"$10 Off Coupon",
"amount":10
}
],

Facebook Templates can be sent using ChannelData. Here is an example of a receipt template with adjustments:
await context.sendActivity({
text: 'Receipt',
channelData: {
"attachment":{
"type":"template",
"payload": {
"template_type": "receipt",
"recipient_name": "Stephane Crozatier",
"order_number": "12345678902",
"currency": "USD",
"payment_method": "Visa 2345",
"order_url": "http://petersapparel.parseapp.com/order?order_id=123456",
"timestamp": "1428444852",
"address": {
"street_1": "1 Hacker Way",
"street_2": "",
"city": "Menlo Park",
"postal_code": "94025",
"state": "CA",
"country": "US"
},
"summary": {
"subtotal": 75.00,
"shipping_cost": 4.95,
"total_tax": 6.19,
"total_cost": 56.14
},
"adjustments": [{
"name": "New Customer Discount",
"amount": 20
},
{
"name": "$10 Off Coupon",
"amount": 10
}
],
"elements": [{
"title": "Classic White T-Shirt",
"subtitle": "100% Soft and Luxurious Cotton",
"quantity": 2,
"price": 50,
"currency": "USD",
"image_url": "http://petersapparel.parseapp.com/img/whiteshirt.png"
},
{
"title": "Classic Gray T-Shirt",
"subtitle": "100% Soft and Luxurious Cotton",
"quantity": 1,
"price": 25,
"currency": "USD",
"image_url": "http://petersapparel.parseapp.com/img/grayshirt.png"
}
]
}
}
}
});

Related

Orders are not displayed at merchant console

I have developed an app in nodejs where I have integrated the Mastercard payment method and it was working fine till Friday. But now when I send money from MasterCard to the merchant account it gives the success response but there is nothing on the merchant console. here is my response
"paymentInfoList": [
{
"url": "https://test-gateway.mastercard.com/api/rest/version/57/merchant/merchant/order/order-1598868168410/transaction/transaction-1598868195864",
"mthd": "PUT",
"payload": {
"apiOperation": "CAPTURE",
"transaction": {
"amount": "1144",
"currency": "USD",
"reference": 1598868195864
}
},
"resbody": {
"authorizationResponse": {
"cardSecurityCodeError": "M",
"commercialCardIndicator": "1",
"date": "0831",
"financialNetworkCode": "MCC",
"posData": "1025104006600",
"posEntryMode": "812",
"processingCode": "000000",
"responseCode": "00",
"stan": "204684",
"time": "100313",
"transactionIdentifier": "0114GR"
},
"gatewayEntryPoint": "WEB_SERVICES_API",
"merchant": "GTB123456D00",
"order": {
"amount": 1144,
"certainty": "FINAL",
"chargeback": {
"amount": 0,
"currency": "USD"
},
"creationTime": "2020-08-31T10:03:13.631Z",
"currency": "USD",
"id": "order-1598868168410",
"lastUpdatedTime": "2020-08-31T10:03:33.156Z",
"merchantAmount": 1144,
"merchantCategoryCode": "5399",
"merchantCurrency": "USD",
"reference": "1598868168410",
"status": "CAPTURED",
"totalAuthorizedAmount": 1144,
"totalCapturedAmount": 1144,
"totalRefundedAmount": 0
},
"response": {
"acquirerCode": "00",
"acquirerMessage": "Approved",
"cardSecurityCode": {
"acquirerCode": "M",
"gatewayCode": "MATCH"
},
"gatewayCode": "APPROVED"
},
"result": "SUCCESS",
"sourceOfFunds": {
"provided": {
"card": {
"brand": "MASTERCARD",
"expiry": {
"month": "9",
"year": "21"
},
"fundingMethod": "CREDIT",
"issuer": "AFRILAND FIRST BANK",
"number": "512345xxxxxx0008",
"scheme": "MASTERCARD",
"storedOnFile": "NOT_STORED"
}
},
"type": "CARD"
},
"timeOfLastUpdate": "2020-08-31T10:03:33.156Z",
"timeOfRecord": "2020-08-31T10:03:33.064Z",
"transaction": {
"acquirer": {
"batch": 20200831,
"date": "0831",
"id": "GTB_S2I",
"merchantId": "mymerchant",
"settlementDate": "2020-08-31",
"timeZone": "+0100",
"transactionId": "0114GR"
},
"amount": 1144,
"authorizationCode": "010602",
"currency": "USD",
"id": "transaction-1598868195864",
"receipt": "024410204684",
"reference": "1598868195864",
"source": "INTERNET",
"stan": "205744",
"terminal": "GTBS2I04",
"type": "CAPTURE"
},
"version": "57"
}
}
]
now you can see the response is success but it doesnot display on merchant panel/console
It was the issue of the merchant panel/console. It didn't display the orders the same day but from the next day it was working fine and all the previous orders were there, and new orders were also showing on the console/panel So it was their server problem.

Azure API Set-body JSON to JSON covert

The response i am getting is below Which i need to convert the input JSON Format to other JSON structure and send the response back. I am struck how to get the data from the JSOn and construct the new JSON format
{
"totalSize": 1,
"done": true,
"records": [{
"attributes": {
"type": "test123",
"url": "/services/data/testapp"
},
"Id": "8373837",
"Name": "6294",
"Application": "9932932932",
"contact": {
"attributes": {
"type": "testcon",
"url": "/services/data/testappsss"
},
"Name": "testName",
"FirstName": "test",
"LastName": "name",
"MailingStreet": null,
"MailingCity": null,
"unemail": "testname#test,.co",
"MailingState": null,
"MailingCountry": null,
"MailingPostalCode": null,
"stuId": "328237832"
},
"currentusbss": "83277832873278",
"currentsu": {
"attributes": {
"type": "testsub",
"url": "/services/data/v44.0jsjsj"
},
"price": 2,
"Name": "SUB-20426"
},
"bal": 234,
"startdate": "2020-02-03",
"enddate": "2020-05-03"
}]
}
I need to convert above JSON format to below JSON format and send it using set-body method in out-bond policies
{
"info": {
"studentName": "testName",
"studentFirstName": "test",
"studentMiddleName": "",
"studentLastName": "Name",
"studentEmail": "testname#test,.co",
"role": "STUDENT",
"billingCountryCode": "US",
"systemId": "XX",
"stuId": "328237832"
},
"address": {
"address1": "1234 Grove St",
"address2": "",
"city": "Tempe",
"countryCode": "US",
"countryDescription": "UNITED STATES",
"stateCode": "AZ",
"stateDescription": "Arizona",
"postalCode": "45235",
"foreignState": "Arizona",
"region": "Domestic",
"phoneNumber": ""
},
"account": {
"institutionId": "1",
"paymentPlan": "N",
"currencyDesc": "United States Dollars",
"currencyType": "USD",
"bal": 234,
"daysLate":"18",
"opportunityId": "9932932932",
"studentParameterName": null,
"studentParameterValue": null
},
"studentTerms": [
{
"startdate": "2020-02-03",
"enddate": "2020-05-03",
"Name": "SUB-20426",
"description": "XQYember 03, 2020 "
}
]
}
You can use Liquid Template for this case:
Using Liquid Templates in Azure API Management
Using Liquid templates with set body
Or you create a new body in the outbound-section with a new JObject

How to setup Partial Authentication using Authorize API

Okay I am setting up Partial Payments via the Authorize.net API in order to enable multiple cards to be used to cover a single balance/charge.
I'm assuming thier Partial Auth feature covers my use case, but in testing, there is an issue I can show you using the API live console here: https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card
Go to the link above and authorize partial payments with the request I edited below and you will notice when you press submit you get a splitTenderId:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "5KP3u95bQpv",
"transactionKey": "346HZ32z3fP4hTG2"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "462.25",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
},
"lineItems": {
"lineItem": {
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
}
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "99999456654"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "emailCustomer",
"settingValue": "true"
}, {
"settingName": "allowPartialAuth",
"settingValue": "true"
},
]
},
"userFields": {
"userField": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
}
}
}
}
This is only successful because the amount is 462.25 as the docs say to use for testing, if I use any other (real) amount the splitTenderId is not there.
Here is a new example request, you can post this again on the link above:
{
"createTransactionRequest": {
"merchantAuthentication": {
"name": "5KP3u95bQpv",
"transactionKey": "346HZ32z3fP4hTG2"
},
"refId": "123456",
"transactionRequest": {
"transactionType": "authCaptureTransaction",
"amount": "462",
"payment": {
"creditCard": {
"cardNumber": "5424000000000015",
"expirationDate": "2020-12",
"cardCode": "999"
}
},
"lineItems": {
"lineItem": {
"itemId": "1",
"name": "vase",
"description": "Cannes logo",
"quantity": "18",
"unitPrice": "45.00"
}
},
"tax": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"duty": {
"amount": "8.55",
"name": "duty name",
"description": "duty description"
},
"shipping": {
"amount": "4.26",
"name": "level2 tax name",
"description": "level2 tax"
},
"poNumber": "456654",
"customer": {
"id": "99999456654"
},
"billTo": {
"firstName": "Ellen",
"lastName": "Johnson",
"company": "Souveniropolis",
"address": "14 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"shipTo": {
"firstName": "China",
"lastName": "Bayles",
"company": "Thyme for Tea",
"address": "12 Main Street",
"city": "Pecan Springs",
"state": "TX",
"zip": "44628",
"country": "USA"
},
"customerIP": "192.168.1.1",
"transactionSettings": {
"setting": [
{
"settingName": "emailCustomer",
"settingValue": "true"
}, {
"settingName": "allowPartialAuth",
"settingValue": "true"
},
]
},
"userFields": {
"userField": [
{
"name": "MerchantDefinedFieldName1",
"value": "MerchantDefinedFieldValue1"
},
{
"name": "favorite_color",
"value": "blue"
}
]
}
}
}
}
And with the 462 amount entered this is no longer a partial auth payment and I no longer get a splitTenderId.
Can someone please help me figure out what is going on?

Get variable from Adaptive card `Action.Submit` in Botframework

How can I get the value when user clicks the button? I have this example card.
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"speak": "<s>Your meeting about \"Adaptive Card design session\"<break strength='weak'/> is starting at 12:30pm</s><s>Do you want to snooze <break strength='weak'/> or do you want to send a late notification to the attendees?</s>",
"body": [
{
"type": "TextBlock",
"text": "Adaptive Card design session",
"size": "large",
"weight": "bolder"
},
{
"type": "TextBlock",
"text": "Conf Room 112/3377 (10)",
"isSubtle":true
},
{
"type": "TextBlock",
"text": "12:30 PM - 1:30 PM",
"isSubtle":true,
"spacing":"none"
},
{
"type": "TextBlock",
"text": "Snooze for"
},
{
"type": "Input.ChoiceSet",
"id": "snooze",
"style":"compact",
"value": "5",
"choices": [
{
"title": "5 minutes",
"value": "5",
"isSelected": true
},
{
"title": "15 minutes",
"value": "15"
},
{
"title": "30 minutes",
"value": "30"
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Snooze",
"data": { "x": "snooze" }
},
{
"type": "Action.Submit",
"title": "I'll be late",
"data": { "x": "late" }
}
]
}
The example is here: http://adaptivecards.io/samples/CalendarReminder.html
How to access it in the session.message object?
I figured it out. In this case it is the x, so to reply it back it would be:
if (session.message && session.message.value) {
// A Card's Submit Action obj was received
session.send(session.message.value.x)
}

Parse large datasets and notify users efficiently

I have a huge dataset that increases by hundreds/thousands items for sale every few minutes. I will be parsing this data as it comes in and I'm looking for suggestions on how to efficiently match new incoming items with users who want the item.
Examples of how other have done this would mean the world to me. Even just clarification on what to search for online would be helpful. I'm having difficulty asking the right questions to search engines so I can learn how to solve this (usually I'm very good at this sort of thing).
Thank you fellow geniuses!
p.s. Hoping so solve this problem with nodejs
Inventory Dataset Example:
{
"anchor": 982179125,
"next_page": 1,
"next_tier": 0,
"num_matches": 47037,
"postings": [
{
"category": "SBIK",
"category_group": "SSSS",
"external_id": "4488716340",
"heading": "60cm Aluminum/Carbon Road Bike, Ultegra/105 equipped, 20-Spd",
"location": {
"accuracy": 8,
"city": "USA-SFO-SNF",
"country": "USA",
"county": "USA-CA-SAF",
"geolocation_status": 3,
"lat": "37.801041",
"locality": "USA-SFO-MRS",
"long": "-122.434151",
"metro": "USA-SFO",
"region": "USA-SFO-SAF",
"state": "USA-CA",
"zipcode": "USA-94123"
},
"price": 800.0
},
{
"category": "SBOT",
"category_group": "SSSS",
"external_id": "4488164318",
"heading": "Burley Bee Boat Trailer",
"location": {
"accuracy": 8,
"city": "USA-SFO-SNF",
"country": "USA",
"county": "USA-CA-SAF",
"geolocation_status": 3,
"lat": "37.7999",
"locality": "USA-SFO-MRS",
"long": "-122.4342",
"metro": "USA-SFO",
"region": "USA-SFO-SAF",
"state": "USA-CA",
"zipcode": "USA-94123"
},
"price": 150.0
},
{
"category": "SAUT",
"category_group": "SSSS",
"external_id": "4459983854",
"heading": "Car frame extra light castom made",
"location": {
"accuracy": 8,
"city": "USA-SFO-SNF",
"country": "USA",
"county": "USA-CA-SAF",
"geolocation_status": 3,
"lat": "37.7999",
"locality": "USA-SFO-MRS",
"long": "-122.4342",
"metro": "USA-SFO",
"region": "USA-SFO-SAF",
"state": "USA-CA",
"zipcode": "USA-94123"
},
"price": 300.0
},
"success": true,
"time_fetch": 9.4971656799316406,
"time_search": 42.315006256103516,
"time_taken": 183.84885787963867
}
My users are looking for:
{name:"tom",wants:"new car"}
{name:"john",wants:"Road Bike",price:[low:100,high:1000]}
{name:"becky",wants:"dolls"}
{name:"sam",wants:"Drobo",price:[low:0,high:500]}]
...
...
...

Resources