-
-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errors in Alan studio script #14
Comments
Got this error |
This happened to me, so I switched to axios and that solved the problem. Turns out that newsapi doesn't like to receive request without headers, especially the User-Agent. So an async await function got the job done, here's how I solved it:
|
can you please give a detailed code beacuse still im not able to get api call properly |
This is the code that gets the first command, you can update it for the rest of the commands:
|
It still gives me error. Can you please share your code ? |
Sure! Just remove that try and it brackets it will work for sure right now
i cant send you the code but this will work and one more suggestion you
should leave this project becoz it will give error after while further in
video as libraries are now updated you should try to do latest videos
project by JSM
…On Thu, 7 Jul 2022, 12:40 pm Mohit Srivastava, ***@***.***> wrote:
It still gives me error. Can you please share your code ?
—
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXIQ2NUOVYR6LMIGSJRLYU3VSZ7FZANCNFSM5XRU6J5A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
let savedArticles = []; intent('Give me the news from $(source* (.*))', (p) => {
async function getArticles(url) {
} }) Please suggest what should be done differently |
intent('give me the news from $(source* (.*))',(p)=>{
let NEWS_API_URL = `
https://newsapi.org/v2/top-headlines?apiKey=${API_KEY}`;
if(p.source.value) {
NEWS_API_URL =
`${NEWS_API_URL}&sources=${p.source.value.toLowerCase().split("
").join('-')}`
api.axios.get(NEWS_API_URL)
.then((response)=>{
let data=response.data.articles
if(!response.data.articles.length) {
p.play("Sorry, please try searching from a different
source");
return;
} else {
const articles = response.data.articles;
savedArticles = articles;
p.play({ command: "newHeadlines",articles });
p.play(`Here are the news from (latest|recent)
${p.source.value}`);
}
})
.catch((error)=> {
p.play("Sorry, an error has occurred");
console.log(error);
});
On Thu, 7 Jul 2022, 2:42 pm Mohit Srivastava, ***@***.***>
wrote:
… Sure! Just remove that try and it brackets it will work for sure right now
i cant send you the code but this will work and one more suggestion you
should leave this project becoz it will give error after while further in
video as libraries are now updated you should try to do latest videos
project by JSM
… <#m_5401511893150747498_>
On Thu, 7 Jul 2022, 12:40 pm Mohit Srivastava, *@*.*> wrote: It still
gives me error. Can you please share your code ? — Reply to this email
directly, view it on GitHub <#14 (comment)
<#14 (comment)>>,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AXIQ2NUOVYR6LMIGSJRLYU3VSZ7FZANCNFSM5XRU6J5A
<https://github.com/notifications/unsubscribe-auth/AXIQ2NUOVYR6LMIGSJRLYU3VSZ7FZANCNFSM5XRU6J5A>
. You are receiving this because you commented.Message ID: @.*>
let savedArticles = [];
intent('Give me the news from $(source* (.*))', (p) => {
let NEWS_API_URL = https://newsapi.org/v2/top-headlines?apiKey=${API_KEY};
if(p.source.value) {
NEWS_API_URL = `${NEWS_API_URL}&sources=${p.source.value.toLowerCase().split(" ").join('-')}`
}
getArticles(NEWS_API_URL);
async function getArticles(url) {
try {
const response = await api.axios.get(url, {
headers: {
'User-Agent': "Mozilla/5.0"
}
});
if(!response.data.articles.length) {
p.play("Sorry, please try searching from a different source");
return;
} else {
const articles = response.data.articles;
savedArticles = articles;
p.play({ command: "newHeadlines", articles });
p.play(`Here are the news from (latest|recent) ${p.SOURCE.value}`);
}
} catch(error) {
p.play("Sorry, an error has occured");
console.log(error);
}
p.play("Would you like me to read the headlines? Please answer by yes or no");
p.then(confirmation);
}
})
Please suggest what should be done differently
—
Reply to this email directly, view it on GitHub
<#14 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXIQ2NXAN5J3KLXXIREMTJLVS2NQRANCNFSM5XRU6J5A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
There is another fix that can be done without using axios.
This snippet can be used in places where the |
The problem is due to api.request requiring additional parameters.
|
thanks for these,really worked |
I guess they have changed the whole syntax in alan studio
neither p.source.value or p.source works, hence no request is being made to the news api and there are many more errors
+1 to the previous issue
please update the script
The text was updated successfully, but these errors were encountered: