how to send data to bb webhook,without sharing webhook url to user? - bots.business

hello friend i am trying to send data to bb webhook,but i dont want that user see my webhook.
normal bb webhook looks like:
https://api.bots.business/v1/bots/185720/new-webhook?&command=urcommand&public_user_token=eb0943059fb548e9faf1283b536c594e&user_id=846515&redirect_to=https%3A%2F%2Ft.me%2yourbot
i know i can send ajax request to bb webhook by following code:
$.ajax({
type: "POST",
url: url,
data: {
content: message
},
success: success,
dataType: "json"
});
But for this i need webhook url for certain user but how to get it anyone knows?
if anyone knows answer please.

You can create private webhook for user only. Not for all bot:
code:
let webhookUrl = Libs.Webhooks.getUrlFor({
// this command will be runned on webhook
command: "/onWebhook",
user_id: user.id,
})
So this webhook will be called only for user with user.id
It is not available for another user.
We can not hide any information on client side. We can obfuscate it only.
But it is not looks good for web request
You can create your own server that will be:
receive AJAX request from your web page
send request to webhook url
so webhook url will be only in your server side app

Related

Make an API request on call end in twilio

I am looking for a way to say 'Thank you' and also make an API call at the end of function execution in Twilio.
Something like this:
responseObject = {
"actions": [
{
"say": "Thank you!"
},
{
"redirect": {
"uri": "API_LINK",
"method": "POST"
}
}
]
}
Sadly, twilio ignores every other message if you have a redirect. I tried to solve this by redirecting to TwiML first:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Thank you!</Say>
<Redirect method="POST">API_LINK</Redirect>
</Response>
But the above also does not work - It says application error after 'Thank you!' at the end. Also, I am passing query parameters along with API call: https://example.link?a=value&b=value. Not sure, how to pass that with TwiML.
This API request is supposed to send message to microsoft teams channel.
Twilio developer evangelist here.
To start with, it seems like you are talking about the end of an Autopilot dialogue, not the end of function execution. If that is the case, you are getting errors because you are mixing Autopilot Actions and TwiML. When you are interacting with an Autopilot assistant you should only respond to it with Actions JSON, not with TwiML.
Also, Autopilot will expect all responses to requests that it makes, including via redirect, to respond with Actions JSON. So it's not recommended to make API requests using a redirect action.
Instead, I would recommend that you use a Twilio Function (or your own back-end) to make your API request from JavaScript and respond with the "say" action.
A Twilio Function might look something like this:
exports.handler = function (context, event, callback) {
// make request to Teams API
// I'm not sure the API method you are using, but use an http client like got, superagent or node-fetch, or a dedicated API client if there is one available
// create your actions
const actions = {
actions: [
{
"say": "Thank you!"
}
]
};
// return the actions JSON
callback(null, actions);
});
Alternatively, you can set up to receive an Autopilot webhook when a dialogue ends. This way you can respond to Autopilot with just the "say" action which will cause the end of the dialogue and trigger the webhook. Then in your webhook handler you can make the API request to Teams.
Let me know if that helps at all.

Communication between client and server in Angular 2+

I am using NodeMailer for mail service. I have to get an email address from a field in client side and send that value to app.js where my nodemailer code resides.
client side
ngOnInit() {
this.forgotForm = this.formBuilder.group({
email: this.email,
});
}
sendmail() {
}
app.js, Nodemailer code (I have to get email id for to address here)
let mailOptions = {
from: 'xyz#gmail.com',
to: '',
subject: 'Test Mailer',
text: 'I am testing Nodemailer to send email.',
};
You Should Consider Looking/ Learning Angular and then going into forms . and then into http modules which will help you post data to services
This is a gist not the actual answer
There are a lots of ways to get this done , using normal inputs and getting data from that input using button control or using Forms[the best approach] as you might have other details to send as well.
There are two kind of froms in Angular Template Driven or Reactive Forms.
After getting the details in your form you will need to post it to a Rest service i am guessing. For that you will need to look at Angular Http Client Module
Please look at those links for more detailed Info on them.
You need to use services in angular in order to do this. in terminal set the path to a folder where you want create service, and then use the command ng generate service <service_name> . This will create a file service_name.service.ts. You can refer https://codecraft.tv/courses/angular/http/overview/ or https://angular.io/tutorial/toh-pt4 for more details.
You can use APIs along with http methods get, post, put, delete etc. to complete your task.
In respective component.ts file create a variable email like:
email =string;
In the html file bind the input field with ngModel as:
[(ngModel)]="email"
Then make a function in service.ts that accepts email as arguments
endMail(email) {
//make api call using http method(say post)
// supply email
let url = <APIURL>
return http.post(url, {email: email});
}
Again in component.ts import this service and instantiate in constructor and use a method to call service

How to authorize for Amazon's Alexa API?

I want to send a request to this Amazon Alexa API.
That page contains the last 50 activities I made with my Amazon Echo. The page returns JSON. Before you can request that page, you need to authorize your account, so the proper cookies are set in your browser.
If I do something simple as:
const rp = require("request-promise");
const options = {
method: "GET",
uri: "https://alexa.amazon.com/api/activities?startTime=&size=50&offset=-1",
json: true
};
rp(options).then(function(data) {
console.log(data);
}).catch(function(err) {
console.log(err);
});
I can send a GET request to that URL. This works fine, except Amazon has no idea it's me who's sending the request, because I haven't authorized my NodeJS application.
I've successfully copied ~10 cookies from my regular browser into an incognito tab and authorized that way, so I know copying the cookies will work. After adding them all using tough-cookie, it didn't work, unfortunately. I still got redirected to the signin page (according to the error response).
How do I authorize for this API, so I can send my requests?
I have been looking for a solution for this too. The best idea I have is to use account linking, but I haven't try it yet. Looks like ASK-CLI has interface for this also, but I can't figure it out how to use it (what is that URL?). For linking account to 3rd party server is not easy, but link it back to Amazon for the json API should not be that complicated.

How to set kik bot webhook

I am trying to setup my first test bot in kik messanger , tried to set up webhhok using php:
https://api.kik.com/v1/config?botname:token/?webhook=https://example.com
Please advise, how to set up webhook using php url (For Telegram bot such request works fine).
Thank you
You need to use a POST and not a GET. I used Postman. After setting Basic Auth header with your bot username and API key, then Content-type header to "application/json", I changed the body type to "raw" and just entered in the json data I wanted my config to be:
{
"webhook": [your webhook url here],
"features": {
"receiveReadReceipts": false,
"receiveIsTyping": false,
"manuallySendReadReceipts": false,
"receiveDeliveryReceipts": false
}
}
When I sent the request, the response had my config data returned in the response. This also worked when I needed to change one of the config parameters. Hope this helps.

shopify - nodejs - get permanent token fails

I have written an application that talks with the shopify API. I manage to get the temporary code from shopify and redirect back to my app where I store the code to later exchange for the permanent token.
According to the docs all I need to do is then send a POST request to https://{shop}.myshopify.com/admin/oauth/access_token with the client_id, client_secret and code is the body of the request.
I am using the request module to send the request and have it set up to send the request as such:
var options = {
method: POST,
url: https://my-develop-shop.myshopify.com/admin/oauth/access_token,
json: true
};
var _body = {
"client_id": config.get('SHOP_ID'),
"client_secret": config.get('SHOP_SECRET'),
"code": tempCode
}
_body = JSON.stringify(_body);
options.body = _body;
request(options, callback);
However when I send the request it always returns with : error_description: 'Could not find Shopify API application with api_key ' }
The app is installed successfully on the client's shop, so why would this error be returned?
Is there a special header that shopify expects? The docs are so vague.
Why does it not authenticate?
Well I cheated and used the shopify-node-api package. There I just use the exchange_temporary_token method. This api also handles throttling so it's a decent investment in the time you might spend incorporating it.

Resources