Send mail using Mailchimp's API - mailchimp

I created a mail campaign(chose "automated" and "API")
When I try to send a test mail
post: https://us20.api.mailchimp.com/3.0/campaigns/{my_campaign_id}/actions/test
I get a 400, "Cannot send this campaign because it is currently sending" error.
And in the dashboard I can see the status of the campaign is "Sending".
The edit mode of the campaign there is only an option to pause the campaign.
Here is the code(using Node.js) used to send the mail
const request = require('superagent');
request.post(`https://us20.api.mailchimp.com/3.0/campaigns/${CAMPAIGN_ID}/actions/test`)
.set('Content-Type', 'application/json;charset=utf-8')
.set('Authorization', 'Basic ' + new Buffer('any:' + MAILCHIMP_API_KEY).toString('base64'))
.send({
test_emails: [ 'my_mail#gmail.com' ],
send_type: 'html',
})
.end((error, response) => {
if (error) {
res.send({ error });
} else {
res.send({ data: response });
}
});
Could you guys point out how to fix the "sending" error.
Thanks.

According to the MailChimp automation documents you should first pauze the campaign before you can edit it's properties.
I guess you have to wait untill the campaign is done sending before you can send a testmail on it: https://mailchimp.com/help/troubleshooting-automations/.

Related

How to replay conversation through nodeJs using messagebird WhatsApp Business API?

How to test?
get started from this url: https://developers.messagebird.com/docs/whatsapp/getting-started/
var messagebird = require('messagebird')();
my code
messagebird.conversations.reply(data.id, {
'type': 'image',
'content': {
'image': {
'url': 'https://api.faridblaster.my/test',
'caption': 'Bocaahhh3332'
}
}
}, function (err, response) {
if (err) {
return console.log(err);
}
});
the result show me
Expected Output should be
status: 'delivered',
Thanks in advance!
Based on the provided examples, this is the expected status right after you are sending the message.
If you'd like to monitor the status changes for the message, you will have to register a webhook for the message.updated events and you'll get your updates in the reportURL (details here)

How to get space Id of users who have not added Google Chat Bot to their coversation

We are implementing a Google hangout Chat Bot , Which will send proactive notification to the user in domain. To do this Google chat Bot API requires the space Id to send proactive notification to user.
Reference document: https://developers.google.com/hangouts/chat/reference/rest/v1/spaces/list
code :
jwtClient.authorize(function (err) {
if (err) {
console.log(err);
return;
}
else {
chat.spaces.list({
auth: jwtClient
}, function (err, resp) {
if (err)
console.log(err);
else {
chat.spaces.list({
auth: jwtClient
}, function (err, resp) {
if (err)
console.log(err);
else {
var spaceList = resp.data.spaces;
spaceList.forEach(element => {
var spaceUrl = `https://chat.googleapis.com/v1/${element.name}/messages?key=${apiKey}`;
request({
url: spaceUrl,
method: "POST",
headers: {
'Content-Type': 'application/json'
},
json: customMessage
},
function (error, response, body) {
callback(error, body)
}
);
})
};
});
}
});
}
});
}
}
But This API returns space list of only those user , who has added the Bot to their coversation.
Is their any work around to get/create space of/to every user in google domain?
Unfortunately there is no way to extract the Space ID without the user ever interacting with the bot. Allowing this would give the bot ability to spam any user whenever without consent.
I would suggest storing space IDs to a database. So once a user has started a conversation with a bot, you can later message them whenever you want. Adding the bot or interacting with it in a room is the "consent" that is needed for a bot to message a user.

how to send formatted messages to rocketchat from hubot?

I would like to prepare formatted messages to rocketchat from hubot but I can't find any reference for that.
That's my main reference:
http://theprogrammingbutler.com/blog/archives/2011/10/28/hubot-scripts-explained/
I have tried this:
msg.http(url)
.headers("PRIVATE-TOKEN": api_key, Accept: 'application/json')
.get() (err, response, body) ->
try
json = JSON.parse(body)
for issue in json
msg.send "#{issue.title}"
catch error
msg.send "Sistema not found."
console.log(error)
But I would like some more rich and elaborated.
Any sugestion ??
Thanks.
The hubot adapter for Rocket.Chat has a method called customMessage. You can include attachments like you would with slack to achieve rich messages.
To use customMessage use something like this:
robot.adapter.customMessage({
channel: room,
attachments: [
{
title: "New Event",
title_link: "http://example.com/event",
text: "<img src=\"http://example.com/picture\" width=\"20\" /> Event 1234: <br /> urgent event"
}
]
});
I had a similar need. What worked for me was using the image_url field, documented in the realtime API documentation:
module.exports = function(robot) {
robot.respond(/image/i, function(res) {
resposta = robot.adapter.customMessage({
channel: room,
attachments: [
{
title: "Image",
title_link: "http://www.example.com",
image_url: "http://www.example.com/image.png",
text: "This image"
}
]
});
});
};

MS BotBuilder : How can the bot receive parameters and initiate conversation at webchat start

I'm using the direct-line method to communicate with this bot :
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID || config.appId,
appPassword: process.env.MICROSOFT_APP_PASSWORD || config.appPassword
});
// Initialize bot
var bot = universalBot(connector);
var server = restify.createServer();
server.listen(process.env.port || port, function () {
console.log('%s listening to %s', server.name, server.url);
});
var botListener = connector.listen();
server.post('/api/messages', (req, resp) => {
token = req.query.token;
console.log(token); //prints the token to the terminal
botListener(req, resp);
});
var msg = new builder.Message()
.text(notification);
//.address(address)
bot.send(msg, function (err) {
// Return success/failure
res.status(err ? 500 : 200);
res.end();
});
In order to pro-actively send the message i still need the address of the user and conversation id.
Is there a way to obtain these information at the time this initialisation on the browser ;
var bot = {
id: params['botid'] || 'botid',
name: params['botname'] || 'botname',
screen: params['screen'] || null
};
BotChat.App({
directLine: {
//secret: params['s'],
token: params['t'],
//domain: params['domain'],
//webSocket: params['webSocket']
},
user: user, //Need to access this user object at server on the webchat start
bot: bot
}, document.getElementById("BotChatGoesHere"));
Or any other way where the bot can start the conversation when the user loads the html in the browser.
UPDATE : The conversationUpdate dialog serves for triggering and initiating a dialog, but how can I access the parameter (token) and user object sent along, inside conversationUpdate dialog?
Thanks
If I understand you correctly, you want your bot to prompt the user with something like Hi, what can I help you with today? the minute the webchat loads, right? I haven't tried the direct line, always used the provided iframe, and here's what I do in my bot to send the welcome message:
bot.on('conversationUpdate', (message) => {
(message.membersAdded || [])
.filter((identity) => identity.id == message.address.bot.id)
.forEach((identity) => {
const reply = new builder.Message()
.address(message.address)
.text("Hi, How can I help you today?");
bot.send(reply);
});
});
I believe what you are looking for is the backchannel. With this, you can send values to your bot. the backchannel documentation is at the bottom of the readme on that repo.

slack api rtm direct message

I'm using a node package: slack-client to interact with the api at slack. Now with or without using slack-client how do I send a direct message from my bot to a user I want to specify? Here's what have so far with a plain socket connection:
var WebSocket = require('ws')
,ws2 = new WebSocket(myURL); //from rtm start
ws2.on('open', function() {
ws2.send({
"id": 333,
"type": "message",
"channel": "#user1", //User I want to send to
"text": "HEY!!!!"
});
});
ws2.on('message', function(message) {
console.log('received: %s', message);
});
I was hoping that message would go directly to me from the bot but nothing. I get a reply of type hello though? The send details above I got on another post about this but it doesn't work for me. The message Id was one I created.
Ok so when calling the rtm.start via the web api, you would get a list of DM's that would be open for various users otherwise you can easily just open an im with im.open. I'm using the node package slack-client as mentioned in my question so you can do this:
//name of user your bot wants to send a msg to.
var userTest = slack.getUserByName('user1');
slack.openDM(userTest.id, function(res)
{
TestMsg(res.channel.id, 'some other msg');//test function I'm using
});
Next is the TestMsg function:
function TestMsg(userChannelId, msg)
{
request.post({url: 'https://slack.com/api/chat.postMessage',
form: { token: "xxxx-yourbot-token",channel: userChannelId,text: msg ,username: "yourBotNamehere", as_user: false}
}, function(error, response, body){
console.log(response.body);
});
}
I couldn't get it to work yet using the websockets send method but I suppose the api of postMessage will do for now as you can post richly formatted messages with postMessage. Hope this helps someone

Resources