Why am I getting: AskSdk.Request verification failed Error, Missing Certificate for the skill request? - node.js

I got a self hosted skill in Cloud Foundry, that uses Node js, Typescript and Express.
The code looks like this:
const app: express.Application = express()
// Skill entry point
const skill = application.getSkillBuilder.createSkillForWebService()
const adapter = new ExpressAdapter(skill, config.global.verifySignature, config.global.verifyTimestamp)
const PORT = app.listen(process.env.PORT || config.global.port)
app.post("/", adapter.getRequestHandlers())
const listener = app.listen(PORT, function () {
const { address, port } = listener.address() as AddressInfo
logger.debug("%s listening to %s%s", app.name, address, port)
})
So when I deploy into a lower environment and a new instance of the Express adapter is created, I pass false for verify signature and verify timestamp.
And it works when I test it on an Alexa device and on the Alexa developers console.
And when I deploy it into production and a new instance of the Express adapter is created, I pass true for the verify signature and verify timestamp.
And I get this error: AskSdk.Request verification failed Error, Missing Certificate for the skill request
Am I missing something in my code??
Do I need to upload the certificate in the Developers console??
Thanks in advance for your help

Related

How to use Bolt events with the newer Slack API manifests?

I'm building a Slack App using Bolt and I've got the basics working using Socket Mode. The docs say that socket mode apps are not allowed in the public directory, which I do want my App in when it's ready. I've now turned off socket mode and got ngrok working as described here. Slack was able to validate the url anyway.
But what's not working is a slash command. The manifest editor says the url is required for a slash command, but how does that line up with bolt? Are there better docs for non-socket-mode somewhere? It seems like every example of using bolt says "let's use socket mode, it's easy".
Manifest portion:
slash_commands:
- command: /sb
url: https://[my url].ngrok.io/slack/command
Sample code:
const { App } = require('#slack/bolt');
const express = require('express');
const app = express();
const boltApp = new App({
signingSecret: config.slackApp.signingSecret,
token: config.slackApp.token,
endpoints = '/'
});
app.use('/slack/events', boltApp.receiver.router);
Bolt
Slack App Manifests
I got this working with a combination of the following:
setting every url in the manifest (slash_commands, event_subscriptions, interactivity) to https://foo.ngrok.io/slack/
attaching Bolt to an existing Express App, attempting to follow this PR to use app and/or router config prop on ExpressReceiver, but strangely what worked was putting the express app into the router
setting up Bolt like below
Example Code:
const expressApp = express();
...
const boltReceiver = new ExpressReceiver({
router: expressApp,
signingSecret: SLACK_SIGNING_SECRET,
endpoints: '/slack'
});
const boltApp = new App({
token: SLACK_BOT_TOKEN,
receiver: boltReceiver,
appToken: SLACK_APP_TOKEN,
socketMode: false,
});

truffle: Error while creating instance of the contract - no code at address 0x3800e97896c6fdb614b9d011c9344dea32e49047

I have deployed a simple 'HelloWorld' contract on the ethereum node using truffle. I am trying to access and call a function inside the contract with a node API.
Below is the code:
var Web3 = require('web3');
var express = require('express');
const app = express();
app.use(express.json());
const artifact = require('./../ethereumapp/example/smartContract/build/contracts/HelloWorld.json')
const contract = require('truffle-contract');
const HelloWorldContract = contract(artifact);
var web3 = new Web3('http://localhost:8000');
HelloWorldContract.setProvider(web3.currentProvider);
var contractapp = HelloWorldContract.at('0x3800e97896c6fdb614b9d011c9344dea32e49047').catch((err)={
//Error gets thrown here
console.error("Error in creating instance of HelloWorld :"+err)}
);
app.get('/', (req, res)=>{
res.send("Hey! The app is up and running");
});
app.get('/getMessage',(req,res)=>{
console.log('Invoking smart contract...');
res.send(contractapp.getMessage());
});
app.listen(3000, ()=>{
console.log("App started on 3000");
});
I am new to ethereum/truffle and can't find out why this error is thrown. Please provide any sample nodejs code which can help me sort out this.
In my case this error occurred because the contract deployment transaction was running out of gas. Truffle's default gas limit used for deploys is 6721975 (reference: truffle general options).
Here's the help text that appeared for the deployment dry-run explanining the issue:
Error: *** Deployment Failed ***
"LinearLiquidityPool" ran out of gas. Something in the constructor (ex: infinite loop) caused gas estimation to fail. Try:
* Making your contract constructor more efficient
* Setting the gas manually in your config or as a deployment parameter
* Using the solc optimizer settings in 'truffle-config.js'
* Setting a higher network block limit if you are on a
private network or test client (like ganache).

Get my Action’s server URL in (JavaScript) fulfilment code

I am using actionssdk and I build my Action fulfilments using Javascript and node.js + Express.
I am looking for a way to get the url (protocol + host name + port) of the server where the fulfilment is hosted.
Is there a simple way to do this? E.g. in the MAIN intent? Is there some conv-property I can use? Can I get hold of a req-parameter in the MAIN-intent, from which I can deduct hostname etc?
const express = require('express');
const expressApp = express();
const { actionssdk, ... } = require('actions-on-google');
const app = actionssdk({
ordersv3: true,
clientId: ...
});
expressApp.post('/fulfilment', app);
app.intent('actions.intent.MAIN', (conv) => {
let myUrl: string = ... // ???????
...
});
(background: obviously I know myself to where I deployed my fulfilment code. But I have a reusable template for fulfilment code in which I want to refer to the host url, and I do not want to type that in manually each time I develop a new Action).
You can get access to the request object in a middleware via Framework Metadata which is by default of type BuiltinFrameworkMetadata which contains objects used by Express
For example, you can use it like this, which will be ran before each request:
app.middleware((conv, framework) => {
console.log(framework.express.request.headers.host)
})

SendTransaction API Creation For Bitcoin

I'm facing issue on creating sendtransaction API using bitcore SendFrom method here please lookup my API ("http://localhost:3000/bitcoin/api/sendfrom?"""2NFuJDmdvKWP2zB5EfsXqNuYz9AW65tBrAy" 0.001 6 "donation" "seans outpost"") and its getting like "error:A wallet phrase needed and has not set" Anyone can please tell me how to create sendtrasaction API for bitcoin using nodejs and bitcore already i created generateNewaddress and getbalance,getaccounts API's i tested it in postman. please find below nodejs code:
var bitcoinapi = require('bitcoin-node-api');
var express = require('express');
var app = express();
var port =3000;
//Username and password relate to those set in the bitcoin.conf file
var wallet = {
host: 'localhost',
port: 18332,
user: 'test',
pass: 'test123'
};
bitcoinapi.setWalletDetails(wallet);
bitcoinapi.setAccess('default-safe'); //Access control
app.use('/bitcoin/api', bitcoinapi.app); //Bind the middleware to any chosen url
app.listen(3000);
console.log('server is running at port ' +port);
please find below screens:
Did you install and setup BitcoinCore?
You need to run the deamon in BitcoinCore (your "wallet" settings)
Btw. you can use the api of the deamon directly (it's not anymore up to date, but gives you an idea: https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list )

Skype Bot responding with empty body

I'm trying to get a Skype bot up and running based off of the echo example but I'm struggling to make a successful POST to my app. When I send a post to /v1/chat I get back a status of 201 (successful creation), and nothing in the body. My console.log does not print anything either, which leads me to believe that the botService.on('personalMessage', ...) function is not being run. Does anyone have any insight into how these POST requests should be formatted? I cannot seem to find anything in the documentation.
My code:
const fs = require('fs');
const restify = require('restify');
const skype = require('skype-sdk');
const botService = new skype.BotService({
messaging: {
botId: '28:<bot’s id="ID176db9ab-e313-4d76-a60c-bc2a280e9825">',
serverUrl : "https://apis.skype.com",
requestTimeout : 15000,
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET
}
});
botService.on('contactAdded', (bot, data) => {
console.log('contact added');
bot.reply('Hello ${data.fromDisplayName}!', true);
});
botService.on('personalMessage', (bot, data) => {
console.log('message incoming');
console.log(data);
bot.reply('Hey ${data.from}. Thank you for your message: "${data.content}".', true);
});
const server = restify.createServer();
server.post('/v1/chat', skype.messagingHandler(botService));
const port = process.env.PORT || 8080;
server.listen(port);
console.log('Listening for incoming requests on port ' + port);
Final Edit & Solution: I think the problem caused by Heroku somehow(it could be something with their free tier ,1 dyno). After some effort, I uploaded the program to Azure, and it is now working perfectly.
Potential Solution: You need to change the server address in the server.post command. If you run your program in "https:\www.yourwebsite.com/v1/chat" , you need to modify this;
server.post('/v1/chat', skype.messagingHandler(botService));
to this;
server.post('https:\\www.yourwebsite.com/v1/chat', skype.messagingHandler(botService));
Of course, don't forget to specify your app id, bot id, and app secret. If you don't have one, you need to generate a password in your Skype application page.
I have the exact problem with the OP. I followed the tutorial, and it doesn't specify how to modify our code to comply with our server. So, after running the program it only returns this;
{"code":"ResourceNotFound","message":"/ does not exist"}
In the Echo example in the Skype Bot Webpage; it says;
"We'll assume the bot's URL for messaging was set to https://echobot.azurewebsites.net/v1/chat during registration."
Make sure that Procfile and worker processes are setup.
My bot is working fine on heroku itself

Resources