request time from thingsboard.io through its time plugin RPC using MQTT.
will it be accurate.
def getTime():
requestId = '1'
request = {
"method": "getTime",
"params": {}
}
client.publish('v1/devices/me/rpc/request/' + requestId, json.dumps(request))
and subsrcibe to rpc on connect callback.
Related
I'm using twitter account activity api for registering a webhook using autohook wrapper library.
As per the docs the post requests to endpoint (https://api.twitter.com/1.1/account_activity/all/:env_name/webhooks.json) should trigger a get request from my server. that will return a crc based on a crc token and my consumer key.
While im getting code 215 and unable to connect during crc request error message again and again.
Im not sure why get request is not exceuting. here is my server and client code.
server.py
#app.route("/webhook/twitter", methods=["GET", "POST"])
def callback() -> json:
if flask.request.method == "GET" or flask.request.method == "PUT":
print(flask.request.args.get("crc_token"))
hash_digest = hmac.digest(
key=os.environ["consumer_secret"].encode("utf-8"),
msg=flask.request.args.get("crc_token").encode("utf-8"),
digest=hashlib.sha256,
)
return {
"response_token": "sha256="
+ base64.b64encode(hash_digest).decode("ascii")
}
elif flask.request.method == "POST":
data = flask.request.get_json()
logging.info(data)
return {"code": 200}
# Once the code running on the server.
# You can register and subscribe to events from your local machine.
#app.route("/",methods=["GET"])
def callbackget():
return "in GEt"
if __name__ == "__main__":
app.run(debug=True, port=443,ssl_context=context)
client side autohook wrapper:
const { Autohook } = require('twitter-autohook');
(async ƛ => {
const webhook = new Autohook(
{
token:"1218220064610099203-8CnN6G3edmIRGdDpLcR7Bao88mMCUg",
token_secret:"JEavuf3PZmSsXWhmSdtNarFPNBp6BsZzMrLpkEMASkJX5",
consumer_key:"6n7U6KDXxouXDcsLMxdiSKwZ9",
consumer_secret:"o2aKE9TivbTwchJXXZ4XaTyAwtCgtoRO35a9PgdaqMLUBRfv49",
env:"enc"
}
);
// Removes existing webhooks
await webhook.removeWebhooks();
// Listens to incoming activity
webhook.on('event', event => console.log('Something happened:', event));
// Starts a server and adds a new webhook
await webhook.start("https://127.0.0.1:443/webhook/twitter");
// Subscribes to a user's activity
await webhook.subscribe({oauth_token, oauth_token_secret});
})();
What is the right format of the Response for Kinesis Firehose with http_endpoint as destination. Have already gone through the aws link:
https://docs.aws.amazon.com/firehose/latest/dev/httpdeliveryrequestresponse.html#responseformat
I have used the below lambda code in python(integrated in api) as well as with many other options, but keep getting the below error message. The test is performed using the "Test with Demo Data" option
sample code:
def lambda_handler(event, context):
data ={}
headersD = {}
headersD['content-length'] = 0
headersD['content-type'] = 'application/json'
data['requestId'] = 'ed4acda5-034f-9f42-bba1-f29aea6d7d8f'
data['timestamp'] = '1578090903599'
bodyDetail= {}
data['body'] = ''
data['headers'] =headersD
data['statusCode']=200
resp = json.dumps(data)
return resp
error response as seen in the logs:
The response received from the endpoint is invalid. See Troubleshooting HTTP Endpoints in the Firehose documentation for more information. Reason:. Response for request 'request-Id' is not recognized as valid JSON or has unexpected fields. Raw response received: 200 "HttpEndpoint.InvalidResponseFromDestination"
Here is the sample output that worked(in python):
responseBody = {
"requestId": "requestId",
"timestamp": 123456
}
resp = {
"headers": {"Content-Type": "application/json", "Content-Length": 100},
"body": json.dumps(responseBody),
"statusCode": 200
}
return resp
Anyone can help me?.
I want register subscription for user, i use ngrok.
I try use postman it success but in my web it error.
this is my log
[2020-07-20 11:12:52] local.INFO: Error: Client error: `POST https://graph.microsoft.com/v1.0/subscriptions` resulted in a `400 Bad Request` response:
{
"error": {
"code": "InvalidRequest",
"message": "Subscription validation request timed out.",
"inner (truncated...)
this is my validationToken i receive:
array (
'validationToken' => 'Validation: Testing client application reachability for subscription Request-Id: d11e795b-9b06-46ff-b2ba-0df49a6e1c5c',
)
and my code
try {
$graph = new Graph();
$graph->setAccessToken($this->token);
$sub = new Model\Subscription();
$sub->setChangeType("created");
$sub->setNotificationUrl($this->domain. '/api/receive-notification');
$sub->setResource( "users/" . $outlook_id . "/events");
$sub->setClientState('SecretClientState');
$dateTime = new Carbon();
$dateTime->addDays(3);
$sub->setExpirationDateTime($dateTime);
$subResult = $graph->createRequest("POST", "/subscriptions")
->attachBody($sub)
->setReturnType(Model\Subscription::class)
->execute();
dd($subResult);
} catch (\Exception $e) {
dd($e->getMessage());
}
Graph API only allows 4230 minutes into the future.
Change
$dateTime->addDays(3);
to
$dateTime->modify('+4230 minutes');
I'm a Twilio newbie so please be gentle.
I'm creating an Autopilot bot to be used via Alexa that in in some circumstances needs to transfer the voice to a telephone number. I'm using my mobile as the destination for testing. I have written a Function to transfer the call which then calls my mobile. All good so far, but as soon as the call is made the Twilio session ends - the call is received and I hear on my mobile "I'm sorry an application error has occurred". I'm guessing I'm missing parameter to connect the voice session to the call. Where have I gone wrong?
Thanks in advance.
Task:
{
"actions": [
{
"say": "Connecting you"
},
{
"handoff": {
"method": "POST",
"channel": "voice",
"uri": "https://qwerty.twil.io/call-me"
}
}
]
}
Function code:
exports.handler = function(context, event, callback) {
// Get an initialized Twilio API client
const client = context.getTwilioClient();
// Make a new phone call, using our first function
// to provide the TwiML for the call
client.calls.create({
url: 'https://' + context.DOMAIN_NAME + '/voice',
to: '+44MyMobileNumber',
from: '+44MyTwilioNumber'
}, function(err, result) {
console.log('New phone call started...');
console.log(result);
// End our function
callback();
});
};
The answer was to Handoff the call in Autopilot to a Twiml Bin that makes the call.
I have this javascript code that send data to channels
// Note that the path doesn't matter for routing; any WebSocket
// connection gets bumped over to WebSocket consumers
socket = new WebSocket("ws://" + window.location.host + "/chat/");
socket.onmessage = function(e) {
alert(e.data);
}
socket.onopen = function() {
socket.send({"test":"data"});
}
// Call onopen directly if socket is already open
if (socket.readyState == WebSocket.OPEN) socket.onopen();
I'm curios how from message I can get the json {"test":"data"}
here's the view
# Connected to websocket.connect
#channel_session
def ws_connect(message, key):
# Accept connection
message.reply_channel.send({"accept": True})
You implemented the connection callback, but did not implement what should happen when a message arrives the server endpoint. Add add message receive function:
def on_receive(message):
print('test received: {}'.format(message.content['test']))
Register the function in routing.py:
channel_routing = [
route("websocket.connect", ws_connect),
route("websocket.receive", on_receive),
]
The JSON message you send will be stored in message.content which is basically just a python dict.