Facebook Message API - facebook

I am creating a Facebook message. For the moment I am sending a message with title, subtitle, image and a button using the following message data.
var messageData = {
recipient: {
user_ref: recipientId
},
message: {
attachment: {
type: 'template',
payload: {
template_type: 'generic',
sharable: true,
image_aspect_ratio: 'square',
elements: [ {
title: new_title,
subtitle: messageText,
image_url: new_image_url,
default_action: {
type: 'web_url',
url: new_link,
webview_height_ratio: 'tall'
}
}
]
}
},
metadata: "DEVELOPER_DEFINED_METADATA"
}
};
I want to able to add a video in the same Facebook message. Is it possible?
So far, I have seen you can send videos in a separate message but not using a template with title, image, subtitle, etc (https://developers.facebook.com/docs/messenger-platform/send-messages#sending_attachments)

The generic template does not support videos. You can use the attachment API or media template (preferred) to send videos.
However, generic templates with an option to show an actual video are not available.

Related

Algolia autocomplete doesn't go to the selected URL with static sources

ANSWER GetItemURL is only used for keyboard interactions. It is not used for the mouse handling. Mouse handling is done by the rendered HTML (from the template). The simplest approach is to use a a HREF In your template, or an OnClick handler that takes you to another page!
—————————-
I've copied the default autocomplete code for static sources, the completion and filters work, and getItemURL is called correctly, however on click the URL does not change.
I've created a sandbox you can see ithere.
Default code:
const { autocomplete } = window["#algolia/autocomplete-js"];
const autocomplete_id = "#autocomplete-search-box";
function CreateAutoComplete(appid, search_api_key, index_name) {
console.log("CreateAutoComplete Called");
autocomplete({
container: autocomplete_id,
placeholder: "Type T to get completions",
getSources() {
return [
{
sourceId: "links",
getItems({ query }) {
const items = [
{ label: "Twitter", url: "https://twitter.com" },
{ label: "GitHub", url: "https://github.com" }
];
return items.filter(({ label }) =>
label.toLowerCase().includes(query.toLowerCase())
);
},
getItemUrl({ item }) {
console.log("GetItemURL", item);
console.log("returning", item.url);
return item.url;
},
templates: {
item({ item }) {
return item.label;
}
}
}
];
}
});
}
Remember that getItemUrl() is expecting a keyboard interaction (navigate via arrows and click enter) to navigate over to the result URL, not a click.
This is working in your codesandbox, although the redirect is being blocked by Twitter/Github.

Ionic 4 Arrow Functions

I am creating a to do list app with Ionic 4. When the user clicks add a task an alert opens. However when a task is put it the input and the add task button is clicked, nothing happens. I feel like there is an issue with my arrow function but I am not familiar enough with them to spot the problem. I have attached a photo of the bit of code I think is the issue and the link to my github. I would really appreciate feedback and a solution!
To do list github
I see two issues with the code here:
this.tasks = this.taskList.valueChanges();
This returns an observable so you must use an async pipe to retrieve its value within the template such as:
*ngFor="let task of tasks | async"
The input was set for a different name, the input name here is "title" and that is how the data returned within the arrow function should be referenced as well
async addItem(){
let addItem = await this.alertCtrl.create({
header: 'Add a Task',
message: 'Please enter a Task',
inputs: [{
name: 'title',
type: 'text'
}],
buttons:[{
text: 'Cancel',
role: 'cancel'
},{
text: 'Add Task',
handler: data => {
let newTaskRef = this.taskList.push(
{ id: '', title: data.title, status: 'open' }
);
newTaskRef.update( { id: newTaskRef.key } );
}
}]
})
await addItem.present();
}

Titanium: Facebook API: Photo not showing

Starting to pull by hair here, running out of things to try.
I'm taking a photo, and it's not showing. If i use a URL, then it works.
I'm using the API example, so not sure what i'm doing wrong?
The only thing i see on the Facebook page is the message, not the photo.
photoButton.addEventListener('click',function(e){
var image = e.media;
var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'camera_photo.png');
f.write(image);
var blob = f.read();
Titanium.Media.showCamera({
success:function(event) {
Ti.API.debug('Our type was: '+event.mediaType);
if(event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
// send XHR req to post image on Facebook
fb.permissions = ['publish_actions', 'status_update', 'publish_stream', 'read_stream','manage_pages']; // Permissions your app needs
fb.authorize();
var data = {
name : "This is my name",
message : 'This is my message',
caption : "This is the caption",
picture : blob
};
fb.requestWithGraphPath('1234567890/feed', data, 'POST', function(e) {
if (e.success) {
alert(e.result);
} else if (e.error) {
alert(e.error);
} else {
alert('Unknown response');
}
});
} else {
alert("got the wrong type back ="+event.mediaType);
}
},
cancel:function() {
// called when user cancels taking a picture
},
error:function(error) {
// called when there's an error
var a = Titanium.UI.createAlertDialog({title:'Camera'});
if (error.code == Titanium.Media.NO_CAMERA) {
a.setMessage('Овој уред нема камера');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
a.show();
},
saveToPhotoGallery:true,
// allowEditing and mediaTypes are iOS-only settings
allowEditing:true,
mediaTypes:[Ti.Media.MEDIA_TYPE_VIDEO,Ti.Media.MEDIA_TYPE_PHOTO]
});
Ok, this post hold the key: Appcelerator Titanium: Facebook Image Upload fail
The issue is for some reason feeds dont work with the FB module, so you have to use an XHR request:
var endPoint = 'https://graph.facebook.com/v2.1/' + pid + '/photos?access_token='+ acc;
xhr.open('POST',endPoint);
xhr.send({
message: data,
picture: image
});

Select2 with AJAX and Initial Local Data

So I'm trying to get the select2 plugin to work with a Backbone.js / CakePHP app. The idea is that this select2 holds email addresses for contacting people as tasks become completed, but the form is editable. What I want to do is (1) load / display all the already saved email addresses for the task being edited, and (2) I want to still have the select2 perform AJAX searches to list recognized emails.
I keep having this issue where I can either show initial data, OR have the AJAX search feature.
My current code for my select2 box is a Backbone.View, and it looks like:
define([
'backbone',
'jquery',
'jquery.select2'
],
function(Backbone, $, select2) {
var notificationSelector = Backbone.View.extend({
notifications: undefined,
events: {
'change' : 'select2ContactsChanged'
},
initialize: function(attrs) {
this.collection.on('add remove reset', this.render(), this);
this.select2ContactsChanged();
},
render: function() {
var contacts = ["abc#def.com", "joe#banana.com"];
$('.notification-selector').attr('value', contacts);
if(this.select2Control == undefined)
{
// Do Search() + query here
this.select2Control = this.$el.select2({
width: '200px',
placeholder: '#email',
tags: [],
minimumInputLength: 3,
// initSelection: function(element, callback) {
// return $.ajax({
// type: "GET",
// url: "/notifications/fetch/",
// dataType: 'json',
// data: { id: (element.val()) },
// success: function(data) {
// }
// }).done(function(data) {
// console.log(data);
// });
// },
});
}
else
{
// Do Search() + query here
this.select2Control = this.$el.select2({
width: '200px',
placeholder: '#email',
tags: [],
minimumInputLength: 3,
ajax: {
url: '/notifications/search/',
dataType: 'json',
data: function(term, page) {
return {
SearchTerm: term
};
},
results: function(data, page) {
return {
results: data
};
}
}
});
}
},
select2ContactsChanged: function() {
var contacts = this.select2Control.val().split(',');
this.collection.reset(contacts);
}
});
return notificationSelector;
});
I read a response by the creator of Select2 to someone else (https://github.com/ivaynberg/select2/issues/392) in which he says to use a 'custom query' to achieve what seems to be what I want. I'm having trouble finding relevant examples or making enough sense of the docs to figure out what he means.
Can anyone spot what I'm doing wrong / missing?
Thanks for your time!
EDIT
I forgot to mention -- the DOM element this is attached to is <input type="hidden" multiple="true" class="notification-selector select2-result-selectable"></input>
Ok, I finally figured out the solution.
I was misunderstanding $.ajax() -- I did not really think about it actually being an asynchronous call. My code to check for the data being returned from the call was running before the AJAX actually finished, so I was always getting undefined.
I assigned a variable to the AJAX call, and set "async: false", and it worked perfectly.
fetchSetNotifications: function() {
var addresses = $.ajax({
method: 'GET',
dataType: 'json',
context: $('#notifications'),
url: '/Notifications/fetch/',
async: false,
alert(addresses);
}
The jqXHR object I get in 'addresses' then contains the response data I want in the "responseText" attribute.

Extjs 4 creating form instance

i'm new to extjs 4.
I have to use same from in different events
Creating a chapter and
Editing a created chapter
In both the situations all form fields are same
Is it better to use different forms for both the situations or can i use the same form instance in two places.
present i'm doing as follows
buttons: [{
text: 'Save',
handler: function () {
var cform = chapter_form.getForm();
cform.submit({
url: BASE_URL+'courses/chapters/saveChapter',
waitMsg:'Saving Data...',
success: function (res, req) {
cform.reset();
win2.destroy();
},
failure:function(form, action) {
}
});
}
},{
text: 'Update',
handler: function(){
var cuform = chapter_form.getForm();
cuform.submit({
url: BASE_URL+'courses/chapters/updateCourseChapter/'+chp_id,
waitMsg:'Saving Data...',
success: function (res, req) {
cuform.reset();
},
failure:function(form, action) {
}
});
}
}, {
text: 'Cancel',
handler: function () {
win2.destroy();
}
}]
Whats the better way to do?
I'd suggested use the same form for both actions. I usually do not separate update and create server actions. I have a general save action.
On server I check the posted model. If it has Id property set - it means that I should updated entity, otherwise I should create it. You could use ExtJs hidden form field to store the model id.