FB Messenger Message Template - facebook-messenger

How can I achieve this template in fb messenger platform?
It seems that the color of the shirt and the price are both subtitles of the message but there can only be 1 subtitle in a message. So how can achieve where there are two subtitles?
This is my current message tempalate
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Classic T-Shirt",
"image_url":"http://petersapparel.parseapp.com/img/item100-thumb.png",
"subtitle":"Medium Grey %0D%0A s",
"buttons":[
{
"type":"web_url",
"url":"https://petersapparel.parseapp.com/view_item?item_id=100",
"title":"View details"
},
{
"type":"postback",
"title":"Buy Now!",
"payload":"USER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}

You can only add new lines to the message itself, not to titles or buttons or quick replies
for ex
messageData = {
recipient: {id: recipientId},
message: {
text: "Your First Line \n your second line",
metadata:"DEVELOPER_DEFINED_METADATA"
}};

just add new element.
"message":{
"attachment":{
"type":"template",
"payload":{
"template_type":"generic",
"elements":[
{
"title":"Classic T-Shirt",
"image_url":"<link>",
"subtitle":"Medium Grey %0D%0A s",
"buttons":[
{
"type":"web_url",
"url":"<link>",
"title":"View details"
},
{
"type":"postback",
"title":"Buy Now!",
"payload":"USER_DEFINED_PAYLOAD"
}
]
},
{
"title":"Classic T-Shirt",
"image_url":"<link>",
"subtitle":"Medium Grey %0D%0A s",
"buttons":[
{
"type":"web_url",
"url":"<link>",
"title":"View details"
},
{
"type":"postback",
"title":"Buy Now!",
"payload":"USER_DEFINED_PAYLOAD"
}
]
}
]
}
}
}

Related

Retrieving related elements from MongoDB

I have the following data in MongoDB. Based alone on an id that I have available how can I retrieve all other entries where the player matches the player for my current id.
For example : find who the player for id 12 is, search all other entries that match that player name and return a list of all of them.
[
{_id: '62ecdf342f1193134043964c', id: '12', player: 'David Beckham', team: 'Manchester United'},
{_id: '62ecdf342f1193134043965c', id: '17', player: 'Cristiano Rolando', team: 'Manchester United'},
{_id: '62ecdf342f1193134043966c', id: '22', player: 'Cristiano Rolando', team: 'Juventus'},
{_id: '62ecdf342f1193134043967c', id: '42', player: 'David Beckham', team: 'Real Madrid'},
]
This is the code that I'm using to retrieve the one single entry that matches a specific id and then I'd also like to get the related entries.
export async function getStaticProps({ params }) {
const { db } = await connectToDatabase();
const jerseyA = await db
.collection("Jerseys")
.find({ id: params.jersey })
.sort()
.toArray();
const jersey = JSON.parse(JSON.stringify(jerseyA))[0];
return { props: { jersey } };
}
Now that you know the name, do another fetch like .find({player: jersey.player})
I'm not sure of the output format you want, but here's one way to return all documents that match the "player" name of the given "id".
db.Jerseys.aggregate([
{
"$match": {
// your id goes here
"id": "17"
}
},
{
"$lookup": {
"from": "Jerseys",
"localField": "player",
"foreignField": "player",
"as": "docs"
}
},
{"$unwind": "$docs"},
{"$replaceWith": "$docs"}
])
Example output:
[
{
"_id": "62ecdf342f1193134043965c",
"id": "17",
"player": "Cristiano Rolando",
"team": "Manchester United"
},
{
"_id": "62ecdf342f1193134043966c",
"id": "22",
"player": "Cristiano Rolando",
"team": "Juventus"
}
]
Try it on mongoplayground.net.
Just an addition to #rickhg12hs solution, to ignore the first record. You can use the following query to ignore the first record (where the id also matched) and the others.
db.Jerseys.aggregate([
{
"$match": {
"id": "12"
}
},
{
"$lookup": {
"from": "Jerseys",
"localField": "player",
"foreignField": "player",
"as": "docs"
}
},
{
"$unwind": "$docs"
},
{
"$replaceWith": "$docs"
},
{
"$match": {
"id": {
"$not": {
"$eq": "12"
}
}
}
}
])
A possible javascript translation of it, should be,
export async function getStaticProps({ params }) {
const { db } = await connectToDatabase();
const { jersey: id } = params;
const jerseyA = await db
.collection("Jerseys")
.aggregate([
{
"$match": {
id
}
},
{
"$lookup": {
"from": "Jerseys",
"localField": "player",
"foreignField": "player",
"as": "docs"
}
},
{
"$unwind": "$docs"
},
{
"$replaceWith": "$docs"
},
{
"$match": {
"id": {
"$not": {
"$eq": id
}
}
}
}
]).toArray();
const jersey = JSON.parse(JSON.stringify(jerseyA))[0];
return { props: { jersey } };
}

Logic App - change JSON format using native actions only

I have a below JSON input coming from a source system:
{
"d":{
"results":[
{
"userId":"123",
"employmentType":"Full time",
"employment":{
"compansation":{
"results":[
{
"payments":{
"results":[
{
"payType":"Annual Salary",
"value":"70000"
},
{
"payType":"Annual Leave",
"value":"1000"
},
{
"payType":"Other Payments",
"value":"2000"
}
]
}
}
]
}
}
},
{
"userId":"456",
"employmentType":"Full time",
"employment":{
"compansation":{
"results":[
{
"payments":{
"results":[
{
"payType":"Annual Salary",
"value":"80000"
},
{
"payType":"Annual Leave",
"value":"2000"
},
{
"payType":"Other Payments",
"value":"3000"
}
]
}
}
]
}
}
},
{
"userId":"123",
"employmentType":"Full time",
"employment":{
"compansation":{
"results":[
{
"payments":{
"results":[
{
"payType":"Annual Salary",
"value":"90000"
},
{
"payType":"Annual Leave",
"value":"3000"
},
{
"payType":"Other Payments",
"value":"4000"
}
]
}
}
]
}
}
}
]
}
}
I want to filter "employment/compansation/payments" to use "payType" "Annual Salay" and "Annual Leave" only; and filter out "payType: Other Payments". Then sum both "Annual Salary" and "Annual Leave" and generate final output like:
[
{
"userId":"123",
"employmentType":"Full time",
"totalSalary":"71000"
},
{
"userId":"456",
"employmentType":"Full time",
"totalSalary":"82000"
},
{
"userId":"789",
"employmentType":"Full time",
"totalSalary":"93000"
}
]
Can I achieve this by only using native Logic App actions? Without using Functions or even JavaScript code? And how?
You can use the "Filter Array" connector in Logic App.
This might be a duplicate question, with similar question being answered here.

How to display Json multiple data in html Nativescript

I have this JSON, I need to display all data like below:
res {
"StatusCode": 0,
"StatusMessage": "OK",
"StatusDescription": [
{
"sensors": [
{
"serial": "sensor1",
"id": "1"
},
{
"serial": "sensor2",
"id": "2"
},
{
"serial": "sensor3",
"id": "3"
}
],
"HBP_id": "12",
"HB_id": "123",
"serial_number": "hb1",
"note": "test"
},
{
"sensors": [
{
"serial": "sensor4",
"id": "4"
},
{
"serial": "sensor5",
"id": "5"
},
{
"serial": "sensor6",
"id": "6"
}
],
"HBP_id": "23",
"HB_id": "234",
"serial_number": "hb2",
"note": "test"
},
{
"sensors": [
{
"serial": "sensor7",
"id": "7"
},
{
"serial": "sensor8",
"id": "8"
}
],
"HBP_id": "34",
"HB_id": "345",
"serial_number": "hb3",
"note": "test"
}
]
}
I want to display in html Nativescript these data:
Product 1:
Serial:
hb1
Sensors:
sensor1
sensor2
sensor3
Serial:
hb2
Sensors:
sensor3
sensor4
sensor5
Serial:
hb3
Sensors:
sensor7
sensor8
I tried this code, but with this I can show only for first data:
<ListView [items]="items" (itemTap)="onItemTap($event)">
<ng-template let-item="item" let-i="index" let-odd="odd" let-even="even">
<StackLayout [class.odd]="odd" [class.even]="even">
<Label [text]="item.serial_number"></Label>
<Label *ngFor="let subItem of item?.sensors" [text]="subItem.serial"></Label>
</StackLayout>
</ng-template>
</ListView>
component.ts:
public items: Items[];
constructor(private service: ItemsService) {
}
public ngOnInit() {
this.getallitems();
}
getallitems() {
this.service.itemsGetAll().subscribe(
items=> {
console.log('itemsfrom ws',items) // show all
this.items= items;
}
);
}
service.ts
public itemsGetAll(): Observable<Items[]> {
let headers = new Headers();
headers.append('x-access-token', this.auth.getCurrentUser().token);
return this.http.get(Api.getUrl(Api.URLS.itemsGetAll), {
headers: headers
})
.pipe(map((response: Response) => {
console.log('response', response)
let res = response.json();
if (res.StatusCode === 1) {
} else {
return res.StatusDescription.map(hbp => {
return hbp;
});
}
}))
}
Display:
Serial:
hb1
Sensors:
sensor1
sensor2
sensor3
Can you ask me, how to use *ngFor in items? Any idea please?
Update:
I change my html like this:
<StackLayout [class.odd]="odd" [class.even]="even">
<Label *ngFor="let item of items" [text]='"[" + item.serial_number +"] " + item?.sensors'></Label>
</StackLayout>
You should be change to this :
<ListView [items]="items?.StatusDescription" (itemTap)="onItemTap($event)">
//Your code here
</ListView>
Rest of code will be same !!!
you can try this solution
public items: Items[];
constructor(private service: ItemsService) {
}
public ngOnInit() {
this.getallitems();
}
getallitems() {
this.service.itemsGetAll().subscribe(
items=> {
console.log('itemsfrom ws',items) // show all
this.items= items.StatusDescription;
}
);
}

how to use ellipses in highcharts in angular to deal with long names?

i am having a high chart having email ids on x axis that are very long i have included ellipses to cut it short but the problem is it is now showing me email ids like this : " <A HREF="mailto:james.cla... " i am not able to understand why it is appending anchor tag in front of the email ids , kindly help.
here is my controller code :
$scope.chart = {
"type": $scope.chartType,
"series": chartData[0],
"xAxis": {
//labels tilted down to view properly
labels: {
rotation: -20,
// using ellipses in highcharts
formatter: function() {
return(this.value.substring(0,25) + "...");
}
},
"categories": chartData[1],
"title": {
"text": 'Approver name'
}
},
"chart": {
"plotBackgroundColor": 'transparent'
},
"yAxis": {
"title": {
"text": "Record count"
}
},
"title": 'aging data'
};
}
i have only included the formatter: function to make it done .

Association Sample in extjs 4.2:

Can any one please point me to a working example of association (with hasMany and belongsTo) in ExtJS. Please don't point me to Sencha docs or any examples related to Sencha because I had tried almost everything but none of them works...
Running sample (turn on your browser console):
http://jsfiddle.net/4TSDu/52/
Ext.define('My.model.Author', {
extend:'Ext.data.Model',
fields:[
'name'
]
});
Ext.define('My.model.Comment', {
extend:'Ext.data.Model',
fields:[
'emailAddress',
'body'
]
});
Ext.define('My.model.BlogPost', {
extend:'Ext.data.Model',
fields:[
'title',
'body'
],
belongsTo:[
{
name:'author',
instanceName:'author',
model:'My.model.Author',
getterName:'getAuthor',
setterName:'setAuthor',
associationKey:'author'
}
],
hasMany:[
{
name:'comments',
model:'My.model.Comment',
associationKey:'comments'
}
],
proxy:{
type:'ajax',
url:'https://dl.dropboxusercontent.com/u/1015920/Ext/blog-posts.json',
reader:{
type:'json',
root:'data'
}
}
});
My.model.BlogPost.load(1, {
success:function(record, operation){
console.log(record.get('title')); // "some title"
console.log(record.getAuthor().get('name')); // "neil"
console.log(record.comments().getCount()); // 2
}
});
Read more here:
http://extjs-tutorials.blogspot.ca/2012/05/extjs-belongsto-association-rules.html
http://extjs-tutorials.blogspot.ca/2012/05/extjs-hasmany-relationships-rules.html
The sample data used:
{
"data": [
{
"id": 1,
"title": "some title",
"body": "some body",
"author": {"id":1, "name": "neil"},
"comments": [
{
"id":55,
"emailAddress": "user#example.com",
"body": "test comment"
},
{
"id":66,
"emailAddress": "user2#example.com",
"body": "another comment"
}
]
}
]
}

Resources