Custom parameters in message for Quickblox javascript - javascript

I am sending chat message with custom parameters to Quickblox api.
message: {
body: 'something',
date_sent: 'some date',
dialog_id: 'dialog id',
extension: {
save_to_history: 1,
},
markable: 1,
type: dialog.type === 3 ? 'chat' : 'groupchat',
customParameter: 'this is custom param',
},
I am sending this to quickblox like this
QB.chat.send(jidOrOpponentId, message);
When I receive that message on other browser, it comes without my custom parameter.
Does anybody know should this custom parameter be returned to me or not? If not, what is it for, anyway?
I read the docs and there is a section on custom params,but there is no explanation on what are they for and should quickblox return them in response.

Try to put the customParameter into the extension object:
var msg = {
type: 'chat',
body: 'How are you today?',
extension: {
save_to_history: 1,
customParameter: 'Custom parameter'
}
};
var opponentId = 78;
QB.chat.send(opponentId, msg);

Related

Sending Case Reply Email With Proper Reply-To in SuiteScript

I have some functionality that automatically sends an email response when a case is created via someone submitting an email that gets sent to a NetSuite case profile email address. The trouble comes when attempting to set a proper reply-to email address. So far the attempts at creating one don't allow for a successful response directly back into the case record. At first undeliverable messages were being returned until I found an error made in the structure of the address. Now, however, the messages don't appear to make it back to the case records. This is the structure being used:
cases.AAAAA.BBBBB_CCCCC_DDDDD.EEEEE#AAAAA.email.netsuite.com
// AAAAA is the account number
// BBBBB is the internal ID of the case record
// CCCCC is the internal ID of the message record
// DDDDD is the internal ID of the customer record on the case
// EEEEE is a hexadecimal value of unknown sourcing or meaning
I'm thinking maybe part of the problem is that the message record ID is the ID of the message that was sent out from the case, and with what I've been doing it's the ID of the message record saved from the initial incoming email that generated the case in the first place. This leads me to believe that I can't just use the email.send() API with setting a reply-to email address, but I don't see another way to send out the email. Is there anything that I'm missing?
You do not use the email.send() function if you intend on having the customer be able to reply to a Support Case.
Instead, you need to create a Case record (or load an existing one) and then send your email message through that Case record.
Upload the following example script to your File Cabinet and create a Suitelet script, deploy it, and run it. You'll see a simple form that allows you to send out an email via a Case record.
EXAMPLE SCREENSHOT:
CODE:
/**
* #NApiVersion 2.x
* #NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/ui/message', 'N/record', 'N/url', 'N/email'], function (serverWidget, message, record, url, email) {
function onRequest(context) {
var form = serverWidget.createForm({
title: 'Send Email via Support Case'
});
form.addField({
id: 'custom_customer',
label: 'Customer',
type: serverWidget.FieldType.SELECT,
source: record.Type.CUSTOMER
});
form.addField({
id: 'custom_email',
label: 'Email Address (not required)',
type: serverWidget.FieldType.TEXT
});
form.addField({
id: 'custom_messagesubject',
label: 'Message Subject',
type: serverWidget.FieldType.TEXT
});
form.addField({
id: 'custom_messagebody',
label: 'Message Body',
type: serverWidget.FieldType.RICHTEXT
});
form.addSubmitButton({
label: 'Send Email'
});
if (context.request.method === 'POST') {
var customerId = context.request.parameters['custom_customer'];
var customerEmail = context.request.parameters['custom_email'];
var messageSubject = context.request.parameters['custom_messagesubject'];
var messageBody = context.request.parameters['custom_messagebody'];
try {
var caseId = 0;
var errorMsg = '';
var caseRec = record.create({
type: record.Type.SUPPORT_CASE
});
caseRec.setValue({
fieldId: 'company',
value: customerId
});
// You can specify an email address to overide the customer's default
// Useful if you need to use an "Anonymous Customer" record and set the outgoing email address to the correct one
if (customerEmail != '') {
caseRec.setValue({
fieldId: 'email',
value: customerEmail
});
}
caseRec.setValue({
fieldId: 'title',
value: messageSubject
});
caseRec.setValue({
fieldId: 'emailform',
value: true
});
caseRec.setValue({
fieldId: 'outgoingmessage',
value: messageBody
});
caseId = caseRec.save({
ignoreMandatoryFields: true
});
} catch (e) {
errorMsg = JSON.stringify(e);
}
if (caseId > 0 && errorMsg == '') {
var caseUrl = url.resolveRecord({
recordType: record.Type.SUPPORT_CASE,
recordId: caseId
});
form.addPageInitMessage({
message: 'Email sent successfully. <a target="_blank" href="' + caseUrl + '">Open Support Case</a>',
title: "Success!",
type: message.Type.CONFIRMATION
});
} else {
form.addPageInitMessage({
message: "Error occurred while sending case message: " + errorMsg,
title: "Failed",
type: message.Type.ERROR
});
}
}
context.response.writePage(form);
}
return {
onRequest: onRequest
};
});
Using the relatedRecords.activityId will automatically send the email with case reply to address.
email.send({
author: me.id,
recipients: you.id,
subject: 'New Case',
body: emailBody,
// attachments: [fileObj],
relatedRecords: {
activityId: thisCase.id
}
});

What would be the message field in Pubnub.Subscribe when the data has been published via another platform

I am getting my data from a python API and thus publishing the data to my pubnub channel via Python. But for charting I have to rely on javascript and hence for subscribing to the same channel via javascript. My question is that when how would I get messages field while I am listening to the channel. My best guess is that we would need to create a separate variable but how to populate that with my published messages?
Here is my code:
data = cclient.samples.list(meter_name ='checkpoint.pause')
pubnub = Pubnub(publish_key='xxx',subscribe_key='xxx')
def timesTamp(data):
for each in data:
x = each.timestamp
def counterVolume(data):
for each in data:
y = each.counter_volume
pubnub.publish( channel='my_channel', message=y )
Listening Via javascript:
var pubnub = PUBNUB({
publish_key : 'xxx',
subscribe_key : 'xxx'
} );
pubnub.subscribe({
channel: 'my_channel',
message: y
});
var channel = "c3-spline" + Math.random();
eon.chart({
history: true,
channel: channel,
flow: true,
generate: {
bindto: '#chart',
data: {
y: 'y',
labels: false
},
axis : {
x : {
type : 'timeseries',
tick: {
format: '%H:%M:%S'
}
}
}
}
});
The first thing you should do is remove setInterval(function(){}); from you code. This is unnecessary.
Second, if you look at the parameter list within the EON docs you'll notice a message parameter.
This is the same exact callback as found in punub.subscribe and will respond whenever you receive a message on that channel.

Heroku app crashing when null value passed

I've built a web app utilizing the Instagram API. I have the below code in my 'server.js' file, the main file on my node server. The problem is, the 'text' value is often 'null' (whenever an Instagram user does not caption their image). This null value crashes my app. How would I improve this code to account for this situation?
My idea is to provide a default value for 'text' that is inserted whenever 'text' is null.
//Save the new object to DB
Stadium.findOneAndUpdate( {object_id: data.object_id}, { $push: {'photos':
{ img: image.data[0].images.standard_resolution.url,
link: image.data[0].link,
username: image.data[0].user.username,
profile: image.data[0].user.profile_picture,
text: image.data[0].caption.text
}}},
{ safe: true, upsert: false },
function(err, model) {
console.log(err);
}
);
//Send a socket to client with the new image
newImage({
img: image.data[0].images.standard_resolution.url,
link: image.data[0].link,
username: image.data[0].user.username,
profile: image.data[0].user.profile_picture,
text: image.data[0].caption.text
});
Use an unary conditional to check first if the caption even exists
text: image.data[0].caption ? image.data[0].caption.text : 'No caption'

mc:edit do not work in Mailchimp template with Mandrill Javascript API

I'm trying to send emails through the Mandrill API with Mailchimp templates. I am doing this in the cloud code with Parse.com, see here https://www.parse.com/docs/cloud_modules_guide#mandrill. The emails are sent just fine, however, the mc:edit fields are never updated. This is the only content in the template now:
<span mc:edit="ship_id">ship_id</span>
This is what my call in Javascript looks like, hope somebody sees my mistake. I'm running this in Parse.com cloud code if that makes any difference. Thanks a lot!
var Mandrill = require('mandrill');
Mandrill.initialize('api-key');
Mandrill.sendTemplate({
template_name: "Drip campaign",
template_content: [{
name: "ship_id",
content:"Test Test"
}],
message: {
text: "Hi",
subject: "You have new mail",
from_email: "info#example.com",
from_name: "Thomas",
to: [
{
email: "answer#example.com",
name: "Fred"
}
],
"headers": {
"Reply-To": "answer#example.com"
},
"important": false,
"track_opens": true,
"track_clicks": true,
},
async: true
},{
success: function(httpResponse) {
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
}
Ok, so there is nothing wrong with my code, but it seems like the templates are not sent properly from Mailchimp to Mandrill as adding fields such as |NAME| for merge tages or mc:edit="name" just were not populated. At least the code of the Mailchimp template is pretty weird and very nested.
For that reason, I would recommend using your own HTML here, where you enter the merge tages or mc:edits https://mandrillapp.com/templates/.
As far as I understand from your question that you want to send e-mail at the same time you want to dynamically edit the mail content. As you have already used, you can do it via the Mandrill API. I suggest you to use the js files which are downloadable in the link;
https://github.com/jlainog/parse-mandrill-sendTemplate
From the js file in the github account, you can dynamically edit the mail content(must be in your template) via using the tag mc:edit.
For my case working copy of code is below;
Parse.Cloud.define("sendMail", function(request, response) {
var Mandrill = require('cloud/mandrillSend.js');
var sentTo = //Mail address to sent
var subject = //Mail Subject
var fromEmail = //From email
var fromName = //From Name
var sentToName = //Parameters from request
var fullName = //Full Name
Mandrill.initialize('YOUR MANDRILL API KEY');
Mandrill.sendTemplate({
template_name: "MANDRIL TEMPLATE",
template_content: [
{
name: "nameHeader",
content: sentToName,
},
{
name: "mail",
content: sentTo,
},
],
"key": "YOUR MANDRILL API KEY",
message: {
subject: subject,
from_email: fromEmail,
from_name: fromName,
to: [{
email: sentTo,
name: fullName
}],
important: true
},
async: false
}, {
success: function (httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function (httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
For example, in Mandrdil Template there is a span with the id;
<span mc:edit="mail"> test#gmail.com</span>
Hope this helps.
Regards.

Facebook stream.share returns undefined

Why does Facebook stream.share return undefined when a user publish a status or click "Skip"?
I'm currently trying to use this, so if the user doesn't publish the content, no action should happen, but if the user publish the content an action should happen.
How do I do this?
You can use the graph API feed dialog to publish a post and know if it was published or not by the user:
FB.ui(
{
method: 'feed',
message: '',
name: 'name here',
caption: 'caption here',
description: 'description here',
picture: 'picture url here',
link: 'http://yourlinkurlhere.com',
actions : [{name : 'action name', link : 'action link'}]
},
function(response) {
if (response && response.post_id) {
// Post was published
} else {
// Post did get published
}
});

Categories