Using text template with link not showing preview image in Gupshup - gupshup

Here is my snippet from Python
def sendTemplateMessage():
url = "http://api.gupshup.io/sm/api/v1/template/msg"
payload = "channel=whatsapp&source=%s&destination=%s&src.name=%s&disablePreview=%s" % (SENDER_NUMBER, "1234567890", APP_NAME, False)
obj = '{"id": "4234234-7b42-4e23423424-956c-234234","params": ["my text", "https://some-link-with-image/"]}'
obj = quote(obj)
payload = "%s&template=%s" % (payload, obj)
response = requests.post(url, headers=HEADERS, data=payload)
print(response.text)
This correctly sends the message. But there is no preview image for the link, it just shows plain link with other contents. Anybody come across this and have solution?

Related

POST method in Power Query 400 Bad Request

I'm trying to receive data from an API, but it's POST method, so I'm trying to send the data, but it won't
let
body = [COD_INT= "886000", COD_INT_CSO= "0"],
Parsed_JSON = Json.FromValue(body),
Source = Web.Contents("https://apixxxxxxx.yyyyyyyyy.com.br/api/CursosConcluidos",
[
Headers= [#"User-Token" ="673E9CAF-xxxxxxxxxxx-xxx-xx-968"],
Content = Parsed_JSON
]
),
final = Json.Document(Source)
in
final
In Postman it works perfectly
Print from Postman
I tried the same from here but it's the same result
Changing or not the ParsedJSON in Binary gives the same result, 400

Acessing Post Rest Api using Power query

I am new to power BI and power query, I am trying to get the JSon data from Post rest api. But i always get a 400 error. Where am I going wrong.
let
authkey ="Bearer xxxx",
url = "https://example.com/xxx",
body = "{""objectId"":""settlement_entity"",""queryString"":""?itemrefs=settlementreference,itemdescription&perpage=12&includekeyitems=true&includeforeignkeyitems=true&includetimestamp=true&includeadditionalmeta=true""}",
Source = Json.Document(Web.Contents(url,
[
Headers = [#"Authorization"= authkey,#"Content-Type"="application/json"], Content = Text.ToBinary(body)
]
))
in
Source
Ok I fixed the issue the body was missing square bracket
let
authkey ="Bearer xxxx",
url = "https://example.com/xxx",
body = "[{""objectId"":""settlement_entity"",""queryString"":""?itemrefs=settlementreference,itemdescription&perpage=12&includekeyitems=true&includeforeignkeyitems=true&includetimestamp=true&includeadditionalmeta=true""]}",
Source = Json.Document(Web.Contents(url,
[
Headers = [#"Authorization"= authkey,#"Content-Type"="application/json"], Content = Text.ToBinary(body)
]
))
in
Source

?:0: attempt to perform arithmetic on field 'fileSize' (a nil value)

How to resolved error or possible ways to resolved it?
Guys, i've developed plugin using Lua language which can be integrate or run from Adobe's LightRoom Classic. Currently i need to upload or send a file to server but i can not. Everytime i called the POST API which is multipart/form-data error popup "?:0: attempt to perform arithmetic on field 'fileSize' (a nil value)". Not even API is being called this error pops up before API call. after debug I can assure the possible issue is in creating mimeChunks with file type.
I have developed the code like below, can any one help me out with suggestions so that i can able to resolved issue?
local filePath = assert("C:\Users\Ankit\Desktop\Hangman.PNG")
local fileName = LrPathUtils.leafName(filePath)
local mimeChunks = {}
mimeChunks[#mimeChunks + 1] = {
name = 'api_sig',
value = "test value"
}
mimeChunks[#mimeChunks + 1] = {
name = "file",
filePath = filePath,
fileName = fileName,
contentType = "application/octet-stream"
}
local postUrl = "API endpoint"
local result, hdrs = LrHttp.postMultipart(postUrl, mimeChunks)
if result then
LrDialogs.message("Form Values", result)
else
LrDialogs.message("Form Values", "API issue")
end
Eventually image or file path itself cause the issue, there are no such indications or articles related to this functionality, but yes "add-on backslash" will work out for sure. Kindly review the below code for more detailed bifurcation which pass dynamic selected file or image path.
local function uploadFile(filePath)
local fileName = LrPathUtils.leafName( filePath )
local mimeChunks = {}
mimeChunks[ #mimeChunks + 1 ] = { name = 'api_sig', value = "test value"}
mimeChunks[#mimeChunks + 1] = {
name = "file",
filePath = filePath,
fileName = fileName,
contentType = "image/jpeg" --multipart/form-data --application/octet-stream
}
import "LrTasks".startAsyncTask(
function()
local postUrl = "http://cms.local.com/api/v1/upload"
local result, hdrs = LrHttp.postMultipart(postUrl, mimeChunks)
if result then
LrDialogs.message("Image uploaded.", result)
else
LrDialogs.message("Error", "API issue")
end
end
)
end
Above uploadFile method will automatically call the API and post form-data collection. Below code is for call uploadFile function which select all the images from catalog.
for p, photo in ipairs(LrApplication.activeCatalog()) do
uploadFile(assert(photo:getRawMetadata('path')));
end
Above code will help you out the selection of categlog with Adobe's LightRoom Plugin.

Springdoc-openapi external json file with relative path for example request body

I am looking for a way to use a relative path for external JSON files while defining the example request body.
My current definition is like this:
#Operation(requestBody = #RequestBody(description = "Request", content = #Content(schema = #Schema(implementation = Request.class), examples = {
#ExampleObject(
name = "An example request",
value = "{\n" +
"\"token\":\"token\"\n" +
"}",
summary = "Request"
)}
)),summary = "summ", description = "desc")
I want to keep JSON value on an external JSON file.
I know that "externalValue" field can be used instead of "value" to reference an external json file, but it requires a URL. I want to keep it in the project file and use the relative path. I am using Open API v3.
For those who are just looking for external JSON file usage, you can use external JSON file from a URL like this:
#Operation(requestBody = #RequestBody(description = "Request", content = #Content(schema = #Schema(implementation = Request.class), examples = {
#ExampleObject(
name = "An example request",
externalValue = "http://domain/test/example.json",
summary = "Request"
)}
)),summary = "summ", description = "desc")

With VoiceResponce - response.gather() with POST does not send Digits

I have a Twilio number configured to http://66.175.221.103:6543/ivr/860d247f4bc7 with GET.
The below code catches it in the GET and creates a voice response with the welcome message. The action is the same URL but with POST.
itemID = request.matchdict['itemid']
itemData = getItemData(request,itemID)
if itemData is not None:
itemResponses = getItemResponses(request,itemID)
if request.method == 'GET':
#Gather the response and POST to the same ID
response = VoiceResponse()
with response.gather(numDigits=1, action=request.route_url('ivr',itemid=itemID), method="POST") as g:
g.say(itemData["item_desc"],voice="alice", language="en-GB", loop=3)
return twiml(response)
else:
log.debug("*************888")
log.debug(request.POST)
log.debug("*************888")
soption = request.POST.get('Digits', '0')
noption = int(soption)
for resp in itemResponses:
if resp["resp_num"] == noption:
response = VoiceResponse()
response.redirect(request.route_url('ivr',itemid=resp["target_item"]))
return twiml(response)
resp = VoiceResponse()
resp.say("Error, was not able to find a response")
resp.hangup()
return twiml(resp)
That produces the following XML
<Response><Gather action="http://66.175.221.103:6543/ivr/860d247f4bc7" method="POST" numDigits="1"><Say language="en-GB" loop="3" voice="alice">Welcome to the Agricultural Podcast service. To listen to a podcast press 1. To request for new content press 2</Say></Gather></Response>
I press 1 for example and I get this on the post:
[('Called', '+17656133098'), ('ToState', 'IN'), ('CallerCountry', 'LS'), ('Direction', 'inbound'), ('CallerState', ''), ('ToZip', '46952'), ('CallSid', 'CAa127058ffcc4b148e8757ffb9025440c'), ('To', '+17656133098'), ('CallerZip', ''), ('ToCountry', 'US'), ('ApiVersion', '2010-04-01'), ('CalledZip', '46952'), ('CalledCity', 'MARION'), ('CallStatus', 'in-progress'), ('From', '+266696687'), ('AccountSid', 'ACaa8c3038f45a521b83c74789d51af27d'), ('CalledCountry', 'US'), ('CallerCity', ''), ('Caller', '+266696687'), ('FromCountry', 'LS'), ('ToCity', 'MARION'), ('FromCity', ''), ('CalledState', 'IN'), ('FromZip', ''), ('FromState', '')]
The Gather does a POST TO "http://66.175.221.103:6543/ivr/860d247f4bc7" but does not send "Digits" as part of the post.
Any idea why?
For some reason that is not documented in Twilio a get request to an URL cannot perform a post (using Gather) to the same URL. I separated the post and get in separated URLs and now all works fine.

Resources